首先我得到這個高度我想和滾動的特定值來比較值。
$(window).scroll(function (event) {
var scroll = $(window).scrollTop();
var windowHeight = $(window).height();
console.log("window height---> " +windowHeight);
console.log("scroll value----> "+scroll);
if (scroll == windowHeight) {
console.log("---after compare--- ");
}
});
但是,當我比較滾動值然後有時滾動值跳過一些值。
我的滾動值(控制檯):
1.scroll value----> 423
1.window height---> 431
2.scroll value----> 427
2.window height---> 431
3.scroll value----> 432
3.window height---> 431
4.scroll value----> 434
4.window height---> 431
5.scroll value----> 436
5.window height---> 431
如果您發現第二個比較:
2.滾動值----> 427
2.window高度---> 431
不相同滾動值和窗口的高度。滾動值直接從2.滾動值----> 427跳到滾動值----> 432。並跳過431的滾動值。如何比較確切的滾動值與窗口高度。
是的,我也試過這個。但我只需要比較確切的值因爲條件應該只滿足一次。 –