2015-09-27 64 views
0

我有一个div与2滚动。我喜欢滚动到结束时向用户显示一条消息。在Firefox中检测滚动到底部2滚动

这是我的div:

<div id="scrollbox"> 
    <div>this is a test.this is a test.this is a test.this is a test</div> 
    <div>this is a test.this is a test.this is a test.this is a test</div> 
    <div>this is a test.this is a test.this is a test.this is a test</div> 
    <div>this is a test.this is a test.this is a test.this is a test</div> 
    <div>this is a test.this is a test.this is a test.this is a test</div> 
    <div>this is a test.this is a test.this is a test.this is a test</div> 
    <div>this is a test.this is a test.this is a test.this is a test</div> 
    <div>this is a test.this is a test.this is a test.this is a test</div> 
    <div>this is a test.this is a test.this is a test.this is a test</div> 
    <div>this is a test.this is a test.this is a test.this is a test</div> 
    <div>this is a test.this is a test.this is a test.this is a test</div> 
    <div>this is a test.this is a test.this is a test.this is a test</div> 
</div> 

,这是我的CSS:

#scrollbox { 
    width: 300px; 
    height: 150px; 
    overflow: auto; 
} 

,这我的javascript:

$(document).ready(function() { 
    $("#scrollbox").scroll("scroll",function() { 
     if ($(this).scrollTop() + $(this).outerHeight() >= $(this)[0].scrollHeight) { 
      alert(1); 
     } 
    }); 
}); 

当DIV有一个滚动的一切运作良好。 我已经让你可以看到。 http://jsfiddle.net/L5f7qtux/

但是,当div有两个滚动是有问题的。 问题是,当滚动到结尾时,几个消息显示给用户。 我已经让你可以看到。 http://jsfiddle.net/L5f7qtux/1/

注意:此问题仅在Firefox浏览器中。

回答

1

只需更换

$(this).outerHeight() 

$(this)[0].clientHeight 

我与变化分叉它,它在我的FF解决了这个问题。

http://jsfiddle.net/7c1runn4/

好运。

+0

感谢它的工作。 [http://jsfiddle.net/L5f7qtux/2/](http://jsfiddle.net/L5f7qtux/2/) –

+0

正确的地址是:[http://jsfiddle.net/L5f7qtux/3/](http ://jsfiddle.net/L5f7qtux/3/) –