jquery Implementation List automatic scrolling loop scrolling display News _jquery

Source: Internet
Author: User
Tags setinterval

You need to scroll through a small area of the page to display news (announcements, events, pictures, and so on), and stop scrolling and prompt when you hover, and continue scrolling after you leave.

Effect Chart:

On dry Goods

Html:

Copy Code code as follows:

<div id= "News" >
<ul>
<li><a href= "#" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow "Rel=" external nofollow "rel=" external nofollow "rel=" external nofollow "title=" aaaaaaaaaaaaaaa "&GT;AAAAAAAAAAAAAAA" </a></li>
<li><a href= "#" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow "Rel=" external nofollow "rel=" external nofollow "rel=" external nofollow "title=" bbbbbbbbbbbbbbb "&GT;BBBBBBBBBBBBBBB" </a></li>
<li><a href= "#" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow "Rel=" external nofollow "rel=" external nofollow "rel=" external nofollow "title=" CCCCCCCCCCCCCCC "&GT;CCCCCCCCCCCCCCC" </a></li>
<li><a href= "#" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow "Rel=" external nofollow "rel=" external nofollow "rel=" external nofollow "title=" ddddddddddddddd "&GT;DDDDDDDDDDDDDDD" </a></li>
<li><a href= "#" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow "Rel=" external nofollow "rel=" external nofollow "rel=" external nofollow "title=" eeeeeeeeeeeeeee ">eeeeeeeeeeeeeee" </a></li>
<li><a href= "#" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow "Rel=" external nofollow "rel=" external nofollow "rel=" external nofollow "title=" Fffffffffffffff "&GT;FFFFFFFFFFFFFFF" </a></li>
<li><a href= "#" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow" rel= "external nofollow "Rel=" external nofollow "rel=" external nofollow "rel=" external nofollow "title=" GGGGGGGGGGGGGGG "&GT;GGGGGGGGGGGGGGG" </a></li>
</ul>
</div>

Css:
Copy Code code as follows:

Ui,li {
List-style:none;
}
#news {
height:75px;
Overflow:hidden;
}

The key is JS file:
Copy Code code as follows:

$ (function () {
var $this = $ ("#news");
var Scrolltimer;
$this. Hover (function () {
Clearinterval (Scrolltimer);
}, function () {
Scrolltimer = setinterval (function () {
Scrollnews ($this);
}, 2000);
}). Trigger ("MouseLeave");

function Scrollnews (obj) {
var $self = Obj.find ("ul");
var lineheight = $self. Find ("Li:first"). Height ();
$self. Animate ({
"MarginTop":-lineheight + "px"
}, the function () {
$self. CSS ({
margintop:0
). Find ("Li:first"). Appendto ($self);
})
}
})


The main is to hover, setinterval, clearinterval, animate these methods as well as margintop attributes (MarginLeft, top, left, etc.) understanding and application, need to pay attention to, if not add. Trigger ("MouseLeave"), the list does not scroll when the page is initialized, and appendto can move elements directly, that's all.

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.