目前,我有一个 overflow-x:scroll div,我想在页面加载完成时默认关注“category_5”。 默认情况下,用户需要滚动到“category_5”并单击“category_5”。是否可以在第一次加载完成时关注“category_5”?
<div id="category" style="overflow-x:scroll; width:100%; white-space: nowrap; height:20%;">
<a href="index.html"><img id="category_1" width="auto" height="100%" src="icon_1_s.png" style="position: relative; top:25%;"/></a>
<a href="index2.html"><img id="category_2" width="auto" height="100%" src="icon_2_d.png" style="position: relative; top:25%;"/></a>
<a href="index3.html"><img id="category_3" width="auto" height="100%" src="icon_3_d.png" style="position: relative; top:25%;"/></a>
<a href="index4.html"><img id="category_4" width="auto" height="100%" src="icon_4_d.png" style="position: relative; top:25%;"/></a>
<a href="index5.html"><img id="category_5" width="auto" height="100%" src="icon_5_d.png" style="position: relative; top:25%;"/></a>
</div>
提前致谢。
埃里克
最佳答案
通过 jquery,您可以将 .scrollLeft() 与类别 5 的位置(.offset() 或 .position())一起使用。要在 Windows 加载时执行此操作,请查看 onload 事件。
有没有 jquery 的等价物。
关于javascript - HTML overflow-x 设置焦点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24777458/