JavaScript code _javascript tips for implementing horizontal or vertical scrolling of Web page content

Source: Internet
Author: User
The main two parts, one, is the rolling content part of two, JS scrolling code, there are only two words.

first, the traditional rolling code

<marquee scrollamount= "2" loop= "-1" scrolldelay= "0" width= "" ><div > Use JavaScript to achieve the level of news content scrolling! </div></marquee>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Traditional rolling code application effect is relatively single, and often there are browser compatibility issues, such as Firefox on the effect will appear marquee effects ineffective problem.

second, JavaScript implementation of the scrolling effect

<div onmouseover= "Clearinterval (timer1);" onmouseout= "Go ();" > <div id= "News" > <span id= "headnew" > Using JavaScript to achieve the level of news content scrolling 1</span> <script language= " JavaScript "> document.write (horizontal scrolling 2 of news content with JavaScript);" News content document.write ("Use JavaScript to achieve the level of news content scrolling 3"); News content </script> </div> </div>//div tags in the width and other parameters can be adjusted <script language=javascript> functio n Newsscroll () {news.style.pixelleft= (news.style.pixelleft-1)%headnew.offsetwidth;//implement nonbreaking scrolling} function Go () {Timer 1=setinterval (' Newsscroll () ', 30)//Changing the second parameter can change the speed, the smaller the value, the faster the speed. Go (); </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

The above is the complete JS scrolling code, if you want to achieve vertical scrolling, you need to simply modify it, that is, using the style of the Pixtop property can be achieved.

From Tian Yuan Blog
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.