简体   繁体   English

获取长水平div的宽度,并使用javascript找到中间

[英]Getting the width of a long horizontal div and find the middle with javascript

I have a 9000px horizontal div container and I want to find it's middle part. 我有一个9000px的水平div容器,我想找到它的中间部分。

I have this code but its getting the whole width of the window not the container div. 我有这个代码,但它获得窗口的整个宽度而不是容器div。

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

Here's a jsFiddle of the whole code 这是整个代码的jsFiddle

It should not be $(document) instead if the id of the 9000px div is #long_div, see the code below. 如果9000px div的id是#long_div,则不应该是$(文档),请参阅下面的代码。

$(document).ready(function(){
  scrollTo($("#long_div").width()/2, 0);
});

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

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