First, we need the support of the jquery framework (this blog already has the jquery environment, no matter ), add the following functions between JavaScript code
- <SCRIPT type = "text/JavaScript">
- FunctionAutoscroll (OBJ ){
- $ (OBJ). Find ("Ul: First"). animate ({
- Margintop: "-25px"
- }, 500,Function(){
- $ (This).Css ({margintop: "0px"}). Find ("Li: First"). appendto (This);
- });
- }
- </SCRIPT>
This is the rolling function, in which the margintop: "-25px" 25px defines the height of each line of news for you, which is generally the default! Then, you can add the news code to the position where you want to implement rolling news:
XML/html code
- <DivId = "scrolldiv">
- <Ul>
- <Li>This is the first line of rolling news.</LI>
- <Li>This is the second line of rolling news.</LI>
- <Li>This is the third line of rolling news.</LI>
- <Li>This is the fourth line of rolling news.</LI>
- <Li>This is the fifth line of rolling news.</LI>
- <Li>This is the sixth line of rolling news.</LI>
- <Li>This is the seventh line of rolling news.</LI>
- <Li>This is the eighth line of rolling news.</LI>
- </Ul>
- </Div>
Note that the id = "scrolldiv" here is required. Finally, add the scroll effect to the DIV frame, that is, at the bottom of the page, or Add the following between JavaScript code
- <SCRIPT type = "text/JavaScript">
- $ (Document). Ready (Function(){
- Setinterval ('autoscroll ("# scrolldiv") ', 1000)
- });
- </SCRIPT>
Here, autoscroll is the function that starts to be added. The "# scrolldiv" in the brackets is the ID name of the DIV of the rolling news. You can set it freely, but the two parts must be consistent!
Finally, add the CSS style code to this Div:
CSS code
- <Style type = "text/CSS">
- Ul, Li {Margin: 0;Padding: 0}
- # Scrolldiv {Width: 300px;Height: 25px;Line-height: 25px;Border: # CCC 1px solid;Overflow: Hidden}
- # Scrolldiv Li {Height: 25px;Padding-left: 10px ;}
- </Style>
This completes. Update the homepage to see the effect. In {
Undefined
} "> There are also multiple rows of scrolling in the effect preview, and the effects that can be controlled to scroll up and down. You can try other effects more! There are not many codes, but the results are quite good! Good user experience!