admin管理员组文章数量:1327750
I'm trying to create a script which would show div if 500px < scrollTop < 800px otherwise it would be hidden. So if my scroll is from 0 to 500 and from 800 and more it is hidden and between 500 and 800 it is shown. I'm new to javascript but this is what I have tried:
$(document).ready(function(){
$(window).scroll(function(){
if ($(this).scrollTop() > 500) {
$('.myDiv').fadeIn();
} else {
$('.myDiv').fadeOut();
}
if ($(this).scrollTop() > 800) {
$('.myDiv').fadeOut();
}
});
However after scrolling to 800 it bugs and starts endlessly hiding and showing. Any way to fix it please?
I'm trying to create a script which would show div if 500px < scrollTop < 800px otherwise it would be hidden. So if my scroll is from 0 to 500 and from 800 and more it is hidden and between 500 and 800 it is shown. I'm new to javascript but this is what I have tried:
$(document).ready(function(){
$(window).scroll(function(){
if ($(this).scrollTop() > 500) {
$('.myDiv').fadeIn();
} else {
$('.myDiv').fadeOut();
}
if ($(this).scrollTop() > 800) {
$('.myDiv').fadeOut();
}
});
However after scrolling to 800 it bugs and starts endlessly hiding and showing. Any way to fix it please?
Share Improve this question edited Feb 22, 2012 at 22:45 Joseph Stine 1,0221 gold badge12 silver badges23 bronze badges asked Feb 22, 2012 at 22:16 user1207524user1207524 3692 gold badges13 silver badges29 bronze badges1 Answer
Reset to default 6$(window).scroll(function(){
if ($(this).scrollTop() > 800) {
$('.myDiv').fadeOut();
}
else {
if ($(this).scrollTop() > 500) {
$('.myDiv').fadeIn();
} else {
$('.myDiv').fadeOut();
}
}
});
本文标签: javascriptshowhide div using scrollTopStack Overflow
版权声明:本文标题:javascript - showhide div using scrollTop - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742233755a2437695.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论