js
$div.myScroll({
speed:60, //數值越大,速度越慢
});html結構
<div> <ul> <li><p></p></li> <li><p></p></li> <li><p></p></li> </ul> </div>
scroll.js
// JavaScript Document
(function($){
$.fn.myScroll = function(options){
//默認配置
var defaults = {
speed:40, //滾動速度,值越大速度越慢
};
var opts = $.extend({}, defaults, options),intId = [];
function marquee(obj, step){
obj.find("ul").animate({
marginTop: '-=1'
},0,function(){
var s = Math.abs(parseInt($(this).css("margin-top")));
//20是p元素的浮動,s跟總高+浮動進行對比
if(s >= ($(this).find("li").slice(0, 1).height() + 20)){
$(this).find("li").slice(0, 1).appendTo($(this));
$(this).css("margin-top", 0);
}
});
}
this.each(function(i){
var speed = opts["speed"],_this = $(this);
intId[i] = setInterval(function(){
if(_this.find("ul").height()<=_this.height()){
clearInterval(intId[i]);
}else{
marquee(_this);
}
}, speed);
_this.hover(function(){
clearInterval(intId[i]);
},function(){
intId[i] = setInterval(function(){
if(_this.find("ul").height()<=_this.height()){
clearInterval(intId[i]);
}else{
marquee(_this);
}
}, speed);
});
});
}
})(jQuery);免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。