0

I have a 9000px horizontal div container and I want to find it's middle part.

I have this code but its getting the whole width of the window not the container div.

    $(document).ready(function(){
     scrollTo(($(document).width() - $(window).width()) / 2, 0);
});

Here's a jsFiddle of the whole code

IAMTHESTIG
  • 418
  • 1
  • 8
  • 16
  • Possible duplicate of http://stackoverflow.com/questions/294250/how-do-i-retrieve-an-html-elements-actual-width-and-height (maybe that will answer your question) – PherricOxide Oct 13 '12 at 08:50
  • @PherricOxide the question was only getting the width of a div. It doesn't include on getting to the middle part of the div. – IAMTHESTIG Oct 13 '12 at 08:55

1 Answers1

2

It should not be $(document) instead if the id of the 9000px div is #long_div, see the code below.

$(document).ready(function(){
  scrollTo($("#long_div").width()/2, 0);
});
Manjunath Manoharan
  • 4,567
  • 6
  • 28
  • 43