I have an overflow container: auto that spans a document window width of 400% wide. Therefore, my page has a horizontal scrollbar. I also have several divs inside this container with different left positions. I need to get the left position of each container when I click on them. I am using $ (this) .offset (). Left, but that gives me the offset to the left of the div container, which is 0px, and I used $ (this) .position (). Left, but that gives me the same ... any suggestions?
The markup is as follows:
<div id='scroll'> <div id='content'> <div class='container' rel='1'></div> <div class='container' rel='2'></div> <div class='container' rel='3'></div> <div class='container' rel='4'></div> </div> </div>
CSS
#scroll{ position:absolute; width:100%; height:95%; overflow:auto; } #content{ float:left; height:100%; } .container{ height:100%; float:left; }
JQuery
var iMaxSize = $(".container").size(); $("#content").css({width: $(document).width()*iMaxSize +'px' }); $(".container").css({width: $("#content").width()/iMaxSize +'px' });
source share