Simple implementation of rolling news bar

Source: Internet
Author: User

  

When dealing with intermittent seamless rolling of news on pages, the most common method is to copy and append a copy of the content in the rolling area, and then implement the rolling stop effect by controlling and judging the scrolltop of the Rolling Block.

In fact, in many cases, it is easier to implement intermittent seamless rolling through node operations.

The Code is as follows:

<Script language = "JavaScript" type = "text/JavaScript">
Window. onload = function (){
VaR o = Document. getelementbyid ('box ');
Window. setinterval (function () {scrollup (O, 24, 0) ;}, 3000 );
}
/// Rolling master Method
/// Parameter: O Rolling Block object
/// Parameter: d the height of each scrolling Screen
/// Parameter: C the current rolling height
Function scrollup (O, D, C ){
If (D = c ){
VaR T = getfirstchild (O. firstchild). clonenode (true );
O. removechild (getfirstchild (O. firstchild ));
O. appendchild (t );
T. style. margintop = "0px ";
} Else {
C + = 2;
Getfirstchild (O. firstchild). style. margintop =-C + "PX ";
Window. setTimeout (function () {scrollup (O, D, C)}, 20 );
}
}
// Solve the problem that Firefox uses space-based carriage return as a node.
Function getfirstchild (node ){
While (node. nodetype! = 1)
{
Node = node. nextsibling;
}
Return node;
}
</SCRIPT>
<Ul id = "box">
<Li> · Xinhua Daily Telecom: The Music Copyright charges are like "one group of troubles" </LI>
<Li> · modern Express: Can humans marry robots to have children? </LI>
<Li> · Global: bankruptcy of a billionaire club in the United States </LI>
<Li> · modern Express: to let the media seal Ni Zhen to sell Li jiaxin Love Letters </LI>
<Li> · Jinghua Times: Beijing University of Aeronautics and Astronautics student self-made rocket Promotion Day </LI>
</Ul>

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.