[英]jquery: slide-in and slide-out of a box whenn scrolling
With this code the #slidebox is sliding in from the right, after the page is scrolled down 50px. 使用此代码,在页面向下滚动50px之后,#slidebox从右侧滑入。 What do I have to add, when the box should slide out after 150px scrolling?
当框滚动150px后应该滑出时,我必须添加什么? Lines with "<150" conditions did't work for me... Thank you!
条件为“ <150”的行对我不起作用...谢谢!
<script type="text/javascript">
$(function() {
$(window).scroll(function(){
if ($(window).scrollTop() > 50)
$('#slidebox').animate({'right':'0px'},300);
else
$('#slidebox').stop(true).animate({'right':'-430px'},100);
});
});
</script>
UPDATE: This is the working result: 更新:这是工作结果:
$(function() {
$(window).scroll(function(){
if($(window).scrollTop() > 50) {
$('#slidebox').animate({'right': '0px'}, 300);
}
else
$('#slidebox').stop(true).animate({'right':'-430px'},100);
if($(window).scrollTop() > 500) {
$('#slidebox').stop(true).animate({'right':'-430px'},100);
}
});
you can try like that: 您可以这样尝试:
$(function() {
$(window).scroll(function(){
if($(window).scrollTop() > 50) {
$('#slidebox').animate({'right': '0px'}, 300);
}
if($(window).scrollTop() > 150) {
$('#slidebox').stop(true).animate({'right':'-430px'},100);
}
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.