Home > Web Front-end > JS Tutorial > body text

js DIV滚动条随机位置的设置技巧_javascript技巧

WBOY
Release: 2016-05-16 18:58:30
Original
1226 people have browsed it

style后面用于限定DIV样式并加滚动条,这个不多说
关键的地方其实很简单,最后两行Javascript就是了,起作用的只有最后一行:
obj.scrollTop=obj.scrollHeight*(Math.random());
obj.scrollTop:滚动条距离顶部的位置
obj.scrollHeight:流动区域的高度
Math.random():获得一个随机数
很简单,有人可能需要,用就拿去,哈哈
PS:IE6 / IE7 / FF2 测试通过
IE7在本地测试时只是每次打开时滚动条位置才不同,刷新却没有变化,但放到网站上之后就正常了
代码如下:


[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!