A very easy-to-use case of text scrolling, the mouse can be suspended, very easy to use text scrolling

Source: Internet
Author: User

A very easy-to-use case of text scrolling, the mouse can be suspended, very easy to use text scrolling

I have found a lot on the Internet, and the core of the writing is the same. Here I will give you a summary and I can add it to my favorites.

Html:

<Div class = "scroll"> <ul class = "list"> <li> <a href = "#" target = "_ blank"> announcement 1 or winner a </ a> </li> <a href = "#" target = "_ blank"> announcement 2 or winner B </a> </li> <a href = "#" target = "_ blank"> announcement 3 or winner C </a> </li> </ul> </div>

 

Resolution: This method is applicable to the announcement categories that only show one row, as well as the large boxes that show the winning list/lottery results. You can change the list height.

Solution 1:

function autoScroll(obj) {    $(obj).find(".list").animate({        marginTop: "-25px"    }, 1000, function () {        $(this).css({marginTop: "0px"}).find("li:first").appendTo(this);    })}var timer = setInterval('autoScroll(".scroll")', 1000);$(function () {    $(".scroll").hover(function () {        clearInterval(timer);    }, function () {        timer = setInterval('autoScroll(".scroll")', 1000);    })})

 

Solution 2:

function autoScroll(obj) {    //var _t;    function scroll() {        $(obj).find(".list").animate({            marginTop: "-25px"        }, 500, function () {            $(this).css({marginTop: "0px"}).find("li:first").appendTo(this);        })    }    var timer = setInterval(scroll, 2800);    $(obj).hover(        function () {            clearInterval(_t);        },        function () {            timer = setInterval(scroll, 2800);        }    )}$(function () {    autoScroll(".scroll");})

 

Resolution: The functions of the two solutions are the same. They are implemented by changing the value of margin-top and adding the first one to the last one. The first method is to directly write down the running step. The timer can be defined outside the loading function or written in it, but the following content must be written in the loading function; otherwise, it cannot be executed normally.

If it is defined as a function as a whole, You can execute it by calling the functions in the load function.

In the hover Event Callback Function, timer = setInterval () must be written, which means that the timer is assigned to the timer again and the setInterval is directly written, if var timer = setInterval () is written (); then a new timer is redefined, which also does not work.

 

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.