Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Отступ в зависимости от высоты окна браузера (https://javascript.ru/forum/jquery/58854-otstup-v-zavisimosti-ot-vysoty-okna-brauzera.html)

IndigoHollow 14.10.2015 11:34

Отступ в зависимости от высоты окна браузера
 
Пытаюсь изменить css свойство div#stage в зависимости от высоты окна браузера. Подскажите, пожалуйста, где ошибка?

jQuery(document).ready(function () {
	$('#stage').css('margin-top', ($(window).height()*0.2));
});

ksa 14.10.2015 11:53

Цитата:

Сообщение от IndigoHollow
где ошибка?

Просто потестируй свой код по шагам... Проверь работоспособность твоей операции...

ksa 14.10.2015 11:57

Или учись делать тестовые примеры...

<!DOCTYPE html>
<html>
<head>
<meta http-equiv='Content-Type' content='text/html; charset=windows-1251' />
<script src='http://code.jquery.com/jquery-latest.js'></script>
<!--
<script src="https://code.angularjs.org/1.3.9/angular.min.js"></script>
<script src="https://code.angularjs.org/1.3.9/angular-route.js"></script>
-->
<style type='text/css'>
#stage {
	width: 10px;
	height: 10px;
	border: 1px solid;
}
</style>
<script type='text/javascript'>
jQuery(document).ready(function () {
    $('#stage').css('margin-top', ($(window).height()*0.2)+'px');
});
</script>
</head>
<body>
<div id='stage'></div>
</body>
</html>


Часовой пояс GMT +3, время: 15:20.