There is a variable, you need to increase its value by 40 and go back to the original, read, search, delve into, while it is difficult, fail to answer your question. At the bottom, I prepared a code, if it works, the block should move vertically:
var h = document.documentElement.clientHeight, w = document.documentElement.clientWidth, wb = parseInt($('.block').css('height')), peremennaya = (h - wb) / 2; //- та переменная, значение которой должно колебаться в пределах 40px //$(".block").css('top', peremennaya); $(".block").css('left', (w - wb) / 2);
.block { display: block; position: fixed; width: 50px; height: 50px; background: #ccc; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> <div class="block"></div>