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

Tips for setting random positions of js DIV scroll bar_javascript tips

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

The style is used to limit the DIV style and add scroll bars. I won’t say much about this
The key point is actually very simple. The last two lines of Javascript are all it takes. Only the last line works:
obj.scrollTop=obj.scrollHeight *(Math.random());
obj.scrollTop: The position of the scroll bar from the top
obj.scrollHeight: The height of the flow area
Math.random(): Get a random number
Very Simple, someone may need it, just take it, haha
PS: IE6 / IE7 / FF2 passed the test
When IE7 was tested locally, the position of the scroll bar was different every time it was opened, but there was no change when refreshing. Once on the website, it will be normal
The code is as follows:


[Ctrl A select all Note: If you need to introduce external Js, you need to refresh to execute
]<script> var obj = document.getElementById("cc"); obj.scrollTop=obj.scrollHeight*(Math.random()); </script>
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!