問題描述
到達 (window).scroll 上的中間元素 (Reach middle element on (window).scroll)
I don't know what is going wrong? I was trying all to get the #second element when scroll
Here's example with console.log CODEPEN EXAMPLE
$(window).scroll(function(){
var section = $("#second").offset().left,
scrollXpos = $("body").scrollLeft();
if(scrollXpos == section){
console.log("second")
}
else{
console.log("rest")
}
});
參考解法
方法 1:
Apparently opera , ie and firefox works better with
$(document).scrollLeft();
not
$("body").scrollLeft();
and same goes for
$(document, window).scroll(function(){
not
$(window).scroll(function(){
Thx @trendy