上干货
html: ">
Home > Web Front-end > JS Tutorial > body text

jQuery implements automatic circular scrolling of lists and stops scrolling when the mouse is hovering_jquery

WBOY
Release: 2016-05-16 17:23:13
Original
1513 people have browsed it

It is necessary to scroll and display news (announcements, events, pictures, etc.) in a small area on the page, and stop scrolling and prompt when the mouse hovers, and continue scrolling after leaving.

Rendering:
jQuery implements automatic circular scrolling of lists and stops scrolling when the mouse is hovering_jquery jQuery implements automatic circular scrolling of lists and stops scrolling when the mouse is hovering_jquery
Upload the useful information
html:

Copy code The code is as follows:

css:
Copy Code The code is as follows:

ui,li {
list-style: none;
}
#news{
height: 75px;
overflow: hidden;
}

The key is the js file:
Copy code The code is 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"
}, 600, function() {
$self. css({
marginTop: 0
}).find("li:first").appendTo($self);
})
}
})

The main thing is the understanding and application of hover, setInterval, clearInterval, animate methods and marginTop attributes (marginLeft, top, left, etc.). It should be noted that if .trigger("mouseleave") is not added, on the web page The list will not scroll during initialization, and appendTo can directly move elements, that's all.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!