当鼠标滚动到特定位置时,如何才能产生效果?
<div id="target">
<!-- some data here -->
</div>jQuery
var target = $('#target');
if(target.scrollTop() > 10){
alert('');
}发布于 2016-10-25 04:37:49
您可能需要为滚动功能选择整个HTML文档,而不是只选择一个特定的div
jQuery
$(document).scroll(function(){
if ($(window).scrollTop() > 10){
// if the current scroll of the window is greater than 10px
alert('');
}
});发布于 2018-06-17 23:05:44
您需要将代码放在$(window).on('scroll', function(){});中,每次滚动窗口时都会触发,如下所示:
$(window).on('scroll', function(){
var target = $('#target');
if(target.scrollTop() > 10){
console.log("Scrolled 10px");
alert('');
}
});https://stackoverflow.com/questions/32013615
复制相似问题