[英]How to count scrolled pixels to the left/right with jQuery within a Drupal7 page?
用
$(window).scroll(function () {
console.log($(this).scrollTop());
});
您可以計算向上或向下滾動的像素。 但是如何計算從左到右的滾動?
我可以想象看到一個隱藏的固定元素的偏移量,但是不是上面的方法那樣嗎?
編輯:問題是,當使用Drupal時,您需要將jquery封裝在其中
jQuery(function($) {...
我嘗試了在這里找到的解決方案,將窗口對象的作用域限定為
var thisWindow = window;
在jQuery膠囊之外,但它使我的網站崩潰了,並且無法正常工作。
EDIT2:好的-也許也很重要,要注意可能將#main-DIV設置為'overflow-y:hidden;'。 並將其子.region.content-DIV設置為“ overflow-x:scroll;”
我發現我需要直接與滾動dif對話。 聽起來很合理...
$('#main .region-content').scroll(function() {
console.log($('#a-special-div-id').offset().left);
});
做到了。 足夠的解決方法。 thnx的推動!
您可以使用scrollLeft()
函數。 jQuery文檔
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.