javascript - HTML overflow-x 设置焦点

标签 javascript html css overflow

目前,我有一个 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/

相关文章:

javascript - 如何同时激活两个 HTML 按钮

javascript - 异步加载脚本

javascript - jquery 同步 dom 元素值

html - 具有固定宽度的中心导航栏

javascript - 固定侧边栏滚动和停在页脚

php - 从数据库中检索时显示多行文本

html - 当页面元素不断变化和移动时,如何在 Ruby 中进行抓取。

javascript - 如何使用 jQuery 的 attr 方法设置 "style=display:none;"?

javascript - 在 couchdb 文档中使用 javascript 和 html 向现有文档添加字段的最简单方法?

javascript - HTML5 Canvas drawImage 正在降低原始视频的质量