[英]Jquery move object from bottom to top
I have this code to move the box on scroll from top to bottom, but i would like to reverse it, instead from top to bottom i would like to move it from bottom to top. 我有这段代码可以将滚动框从上到下移动,但是我想反转它,而不是从上到下,我想从下到上移动它。 Here's my code guys: 这是我的代码专家:
<script type="text/javascript">
$(document).ready(function() {
$(window).scroll(function() {
var x = $(document).scrollTop();
var wh = $(window).height();
console.log($(document).scrollTop());
$('.box').css('top', x);
});
});
</script>
UPDATE CSS: 更新CSS:
body {
background-image:url('bg.jpg');
height: 20000px;
}
div {
width: 50px;
height: 50px;
background: #f00;
top: 0%;
position: fixed;
}
this codes moves the box from top to bottom, how to move it from bottom to top? 此代码将框从顶部移动到底部,如何将其从底部移动到顶部? thanks guys for your answers. 谢谢你们的回答。
If I understood you correctly, you want to move the box from bottom to top when you're scrolling down. 如果我对您的理解正确,那么在向下滚动时,您希望将框从下至上移动。 Hope this will help. 希望这会有所帮助。
$(window).scroll(function() {
var x = $(document).scrollTop();
var dh = $(document).innerHeight();
var offset = x/dh*100+'%';
$('.box').css('bottom', offset);
});
Would be good if you post your css code. 如果发布您的CSS代码会很好。
But here is one proposal: 但是这里有一个建议:
$('.box').css('bottom', wh);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.