Jquery implements news scrolling

Source: Internet
Author: User

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

  1. <SCRIPT type = "text/JavaScript">
  2. FunctionAutoscroll (OBJ ){
  3. $ (OBJ). Find ("Ul: First"). animate ({
  4. Margintop: "-25px"
  5. }, 500,Function(){
  6. $ (This).Css ({margintop: "0px"}). Find ("Li: First"). appendto (This);
  7. });
  8. }
  9. </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
  1. <DivId = "scrolldiv">
  2. <Ul>
  3. <Li>This is the first line of rolling news.</LI>
  4. <Li>This is the second line of rolling news.</LI>
  5. <Li>This is the third line of rolling news.</LI>
  6. <Li>This is the fourth line of rolling news.</LI>
  7. <Li>This is the fifth line of rolling news.</LI>
  8. <Li>This is the sixth line of rolling news.</LI>
  9. <Li>This is the seventh line of rolling news.</LI>
  10. <Li>This is the eighth line of rolling news.</LI>
  11. </Ul>
  12. </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

  1. <SCRIPT type = "text/JavaScript">
  2. $ (Document). Ready (Function(){
  3. Setinterval ('autoscroll ("# scrolldiv") ', 1000)
  4. });
  5. </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
  1. <Style type = "text/CSS">
  2. Ul, Li {Margin: 0;Padding: 0}
  3. # Scrolldiv {Width: 300px;Height: 25px;Line-height: 25px;Border: # CCC 1px solid;Overflow: Hidden}
  4. # Scrolldiv Li {Height: 25px;Padding-left: 10px ;}
  5. </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!

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.