[英]Scroll to bottom of div event (overflow)
Hi please help me with my fiddle HERE 你好,请帮我摆弄HERE
I have this div 我有这个div
<div id='divdiv' style="height: 200px; overflow:scroll">
<span id='content'>
Scroll down!Scroll down!
Scroll down!Scroll down!
Scroll down!Scroll down!
Scroll down!Scroll down!
Scroll down!Scroll down!
Scroll down!Scroll down!
</span>
<i id="selectedElement">s</i>
</div>
this div has overflow and I have scroll event that trigger when <i id="selectedElement">s</i>
is visible in div 此div溢出,并且我有在
<i id="selectedElement">s</i>
在div中可见时触发的滚动事件
//function to check if target element is visible
function isElementVisible(elementToBeChecked)
{
var TopView = $('#divdiv').scrollTop();
var BotView = TopView + $('#divdiv').height();
var TopElement = $(elementToBeChecked).offset().top;
var BotElement = TopElement + $(elementToBeChecked).height();
return ((BotElement <= BotView) && (TopElement >= TopView));
}
//scroll event
$('#divdiv').scroll(function () {
isOnView = isElementVisible("#selectedElement");
if(isOnView){
$('#content').append('<br>a<br>a<br>a<br>a<br>a<br>a<br>a');
}else{ // If not visible
}
});
if the <i id="selectedElement">s</i>
is visible i added some value '<br>a<br>a<br>a<br>a<br>a<br>a<br>a'
just to test if i reach the bottom but I can't make it work. 如果
<i id="selectedElement">s</i>
是可见的,则我添加了一些值'<br>a<br>a<br>a<br>a<br>a<br>a<br>a'
只是为了测试,如果我到达底部,但我不能使它发挥作用。
it should function as 它应该作为
when the target element is visible i will load some content then user will scroll again to bottom and when the target element is "again" visible i will load some more content again 当目标元素可见时,我将加载一些内容,然后用户将再次滚动到底部;当目标元素“再次”可见时,我将再次加载一些内容
I have updated the fiddle here . 我在这里更新了小提琴。
This appends a random number to the 'content' div as soon as it reaches the bottom. 一旦到达底部,就会在“内容” div后面附加一个随机数。
function appendContent()
{
if ($('#divdiv')[0].scrollHeight <= $('#divdiv')[0].scrollTop + $('#divdiv').height() ) {
return true;
}
else
return false;
}
$('#divdiv').scroll(function () {
if(appendContent()){
$('#content').append('<br>' + Math.random());
}else{ // If not visible
}
});
Check this Demo Fiddle 检查这个演示小提琴
Use this 用这个
$('#divdiv').scrollTop($('#divdiv').prop("scrollHeight"));
OR 要么
$('#divdiv').scrollTop($('#divdiv')[0].scrollHeight);
scrollTop() scrolls the div to the bottom. scrollTop()将div滚动到底部。
prop("scrollHeight") gives your the actual height, and not default display height - height()
. prop(“ scrollHeight”)给出您的实际高度,而不是默认的显示高度-height
height()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.