聯(lián)系官方銷售客服
1835022288
028-61286886
(function ($) {
$.fn.extend({
Scroll: function (opt,callback) {
//參數(shù)初始化
if (!opt) var opt = {};
var _this = this.eq(0).find("ul:first");
var lineH = _this.find("li:first").height(), //獲取行高
line = opt.line ? parseInt(opt.line, 10) : parseInt(this.height() / lineH, 10), //每次滾動(dòng)的行數(shù),默認(rèn)為一屏,即父容器高度
speed = opt.speed ? parseInt(opt.speed, 10) : 500, //卷動(dòng)速度,數(shù)值越大,速度越慢(毫秒)
timer = opt.timer ? parseInt(opt.timer, 10) : 2000; //滾動(dòng)的時(shí)間間隔(毫秒)
if (line == 0) line = 1;
var upHeight = 0 - line * lineH;
var downHeight=line * lineH - 0;
//滾動(dòng)函數(shù)
scrollUp = function () {
_this.animate(
{ marginTop: upHeight },
speed,
function () {
for (i = 1; i <= line; i++) {
_this.find("li:first").appendTo(_this);
}
_this.css({ marginTop: 0 });
}
);
},
//向下滾動(dòng)函數(shù)
scrollDown = function () {
_this.animate(
{ marginTop: downHeight },//動(dòng)畫(huà)展示css樣式
speed,
function () {
_this.find("li:last").prependTo(_this);
_this.css({ marginTop: 0 });
}
)
}
var timerID
//鼠標(biāo)事件綁定
_this.hover(function () {
clearInterval(timerID);
}, function () {
timerID = setInterval("scrollDown()", timer);//這里調(diào)用向下或者向上滾動(dòng)函數(shù)
}).mouseout();
}
})
})(jQuery);
$(document).ready(function () {
$("#news_l").Scroll({ line: 1, speed: 500, timer: 2000 });
});
<div id="news_l">
<ul>
<li><a href="">新聞1</a><span>2017-08-28</span> </li>
<li><a href="">新聞1</a><span>2017-08-28</span> </li>
<li><a href="">新聞1</a><span>2017-08-28</span> </li>
<li><a href="">新聞1</a><span>2017-08-28</span> </li>
<li><a href="">新聞1</a><span>2017-08-28</span> </li>
</ul>
</div>
#news_l{width:100%;height:250px;min-height:25px;line-height:50px;overflow:hidden}
#news_l ul{padding:0 10px}
#news_l li{padding:0 5px ;font-size: 14px; height:49px;border-bottom: 1px dashed #e0e0e0;}
#news_l li span{float: right;line-height: 50px; color:#666;font-size: 14px;}
#news_l li a{color: #666;}
這前端問(wèn)題 讓我看的很醉 就不能代碼高亮?
【蘇先生】1樓
用他的分享帖里面的方法吧,你這個(gè)代碼看著好累啊
