简体   繁体   English

我如何获得水平滚动jQuery的div多少

[英]How can I get how much a div is horizontally scrolled jquery

I have a div with this configurations: 我的div具有以下配置:

<div class="divImagem" style="position:relative; width: 1424px; height: 790px; overflow:hidden;">

Since the div is pretty large, it is not completely shown in the browser screen. 由于div非常大,因此无法完全显示在浏览器屏幕中。 So it creates a horizontal scroll bar for this unique div (not for the whole screen page). 因此,它将为此唯一的div(而不是整个屏幕页面)创建一个水平滚动条。

How can I get how much of the div has scrolled to the left? 如何获得已将div的多少滚动到左侧? I have tried this: 我已经试过了:

$("div.divImagem").scrollLeft();

But it does not work.. it always return me 0, even if the div is horizontally scrolled. 但是它不起作用..即使div是水平滚动的,它也总是返回0。

It's the window that you're scrolling, not the div. 这是您要滚动的窗口,而不是div。

Here's an interactive example: http://jsfiddle.net/pjWt7/1/ 这是一个交互式示例: http : //jsfiddle.net/pjWt7/1/

HTML HTML

<p>Scrolled: <span>0</span>px</p>
<div class="divImagem" style="position:relative; width: 1424px; height: 790px; overflow:hidden;">

Javascript/jQuery 使用Javascript / jQuery的

$(window).scroll(function () {
    console.log("scrolling");
    var scrollLeft = $(this).scrollLeft();
    $("span").html(scrollLeft);

})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM