Javascript 确定已滚动到底部的div的id
简单的问题,简单的观点,在这样的情况下找不到答案。下面的javascript函数在用户滚动到div底部时发出警报。我有许多div,但我只希望在滚动div id=imageloc时运行警报Javascript 确定已滚动到底部的div的id,javascript,jquery,scroll,Javascript,Jquery,Scroll,简单的问题,简单的观点,在这样的情况下找不到答案。下面的javascript函数在用户滚动到div底部时发出警报。我有许多div,但我只希望在滚动div id=imageloc时运行警报 $(window).scroll( function() { if ( document.documentElement.clientHeight + $( document ).scrollTop() >= document.body.offsetHeight ) { if
$(window).scroll( function() {
if ( document.documentElement.clientHeight + $( document ).scrollTop() >= document.body.offsetHeight ) {
if (this.id == "imageloc" ) {
alert("bottom of the page.");
}
}
});
像这样使用
$(window).scroll(function() {
var winTop = $(this).scrollTop();
var $divs = $('div');
var top = $.grep($divs, function(item) {
return $(item).position().top <= winTop;
});
alert($(top).attr('id'));
});
$(窗口)。滚动(函数(){
var winTop=$(this.scrollTop();
变量$divs=$('div');
var top=$.grep($divs,函数(项){
return$(item).position().top像这样使用
$(window).scroll(function() {
var winTop = $(this).scrollTop();
var $divs = $('div');
var top = $.grep($divs, function(item) {
return $(item).position().top <= winTop;
});
alert($(top).attr('id'));
});
$(窗口)。滚动(函数(){
var winTop=$(this.scrollTop();
变量$divs=$('div');
var top=$.grep($divs,函数(项){
return$(item).position().top
当用户滚动到页面时,下面的javascript函数会发出警报
分区的底部。我有许多分区,但我只希望警报运行
滚动div id=imageloc时
$(window).scroll( function() {
if ( document.documentElement.clientHeight + $( document ).scrollTop() >= document.body.offsetHeight ) {
if (this.id == "imageloc" ) {
alert("bottom of the page.");
}
}
});
也许我误解了,但它的措辞就像你有许多可滚动的div,如果其中一个被滚动到底部,你想做些什么。然后你应该听这个特定div上的scroll
事件:
$("#imageloc").scroll( function(e) {
if ( this.scrollTop >= this.scrollHeight - this.offsetHeight ) {
console.log( 'bottom' )
}
});
如果您想在文档已滚动到特定div的底部时执行某些操作,请尝试以下操作:(但是,每当用户滚动窗口且#imageloc位于视口上方时,它都会触发)
当用户滚动到页面时,下面的javascript函数会发出警报
分区的底部。我有许多分区,但我只希望警报运行
滚动div id=imageloc时
$(window).scroll( function() {
if ( document.documentElement.clientHeight + $( document ).scrollTop() >= document.body.offsetHeight ) {
if (this.id == "imageloc" ) {
alert("bottom of the page.");
}
}
});
也许我误解了,但它的措辞就像你有许多可滚动的div,如果其中一个被滚动到底部,你想做些什么。然后你应该听这个特定div上的scroll
事件:
$("#imageloc").scroll( function(e) {
if ( this.scrollTop >= this.scrollHeight - this.offsetHeight ) {
console.log( 'bottom' )
}
});
如果您想在文档已滚动到特定div的底部时执行某些操作,请尝试以下操作:(但是,每当用户滚动窗口且#imageloc位于视口上方时,它都会触发)。您可以尝试类似的操作
var imgLocTop = $('#imageloc').offset().top ;
var $window = $(window);
var limit = Math.abs($window.height() - imgLocTop);
$window.scroll( function() {
if($window.scrollTop() >= limit) {
alert('Reached the required div');
}
});
你可以试试这样的东西
var imgLocTop = $('#imageloc').offset().top ;
var $window = $(window);
var limit = Math.abs($window.height() - imgLocTop);
$window.scroll( function() {
if($window.scrollTop() >= limit) {
alert('Reached the required div');
}
});
这意味着div可能没有id属性。这意味着div可能没有id属性