![](/img/trans.png)
[英]How to find the width of the div or check whether horizontal scroll appears or not?
[英]Getting the width of a long horizontal div and find the middle with javascript
我有一個9000px的水平div容器,我想找到它的中間部分。
我有這個代碼,但它獲得窗口的整個寬度而不是容器div。
$(document).ready(function(){
scrollTo(($(document).width() - $(window).width()) / 2, 0);
});
這是整個代碼的jsFiddle
如果9000px div的id是#long_div,則不應該是$(文檔),請參閱下面的代碼。
$(document).ready(function(){
scrollTo($("#long_div").width()/2, 0);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.