Javascript 我想要jquery代码,在这里我可以在视差页面上比较特定的div';s的滚动顶部为0
我想要jquery代码,在这个代码中,我可以在视差页面上比较某个特定div的Javascript 我想要jquery代码,在这里我可以在视差页面上比较特定的div';s的滚动顶部为0,javascript,jquery,html,scroll,scrolltop,Javascript,Jquery,Html,Scroll,Scrolltop,我想要jquery代码,在这个代码中,我可以在视差页面上比较某个特定div的scrolltop是否为0 $(window).bind('scroll', function() { if ($(window).scrollTop() > 500) { $('#home').css({position: 'relative'}); $('.home').removeClass('active'); } else {
scrolltop
是否为0
$(window).bind('scroll', function() {
if ($(window).scrollTop() > 500) {
$('#home').css({position: 'relative'});
$('.home').removeClass('active');
}
else {
$('#home').css({position: 'fixed'});
}
});
如何修改此代码以比较div是否为特定div
div id='slide5'
位于顶部Html
<div id="id1">Semple page 1<div>
<div id="id2">Semple page 2<div>
<div id="id3">Semple page 3<div>
将
$(窗口)
更改为$('#slide5')
。我建议您阅读的选择器页面,因为这是jQuery中最简单的任务。$(window).scroll(函数(){var styledDiv=$('divtochange'),targetScroll=$('divtocompare').position().top,currentScroll=$('html').scrollTop()| |$('body').scrollTop();styledDiv.toggleClass('makehide',currentScroll>=targetScroll)});如何向它添加时间延迟$(window).scroll(函数(){var styledDiv=$('divtochange'),targetScroll=$('divtocompare').position().top,currentScroll=$('html').scrollTop()| |$('body').scrollTop();styledDiv.toggleClass('makehide',currentScroll>=targetScroll);});在您的条件匹配后,我如何将时间延迟添加到itadd计时器中。
$("#id1").bind('scroll', function (event) {
if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
//Your operation
}
});
$("#id2").bind('scroll', function (event) {
if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
//Your operation
}
});
$("#id3").bind('scroll', function (event) {
if ($(this).scrollTop() + $(this).innerHeight() >= $(this)[0].scrollHeight) {
//Your operation
}
});