【发布时间】:2018-06-16 01:52:57
【问题描述】:
我使用了我在网上找到的这个脚本 (https://codepen.io/erickarbe/pen/gyfFB) 但是在第一个循环之后它只是卡在中间并回到开始,如果你看看它不能正常工作,如果有人能帮我弄清楚它会很棒!
$jQuery.fn.liScroll = function(settings) {
settings = jQuery.extend({
travelocity: 0.03
}, settings);
return this.each(function(){
var $strip = jQuery(this);
$strip.addClass("newsticker")
var stripHeight = 1;
$strip.find("li").each(function(i){
stripHeight += jQuery(this, i).outerHeight(true); // thanks to Michael Haszprunar and Fabien Volpi
});
var $mask = $strip.wrap("<div class='mask'></div>");
var $tickercontainer = $strip.parent().wrap("<div class='tickercontainer'></div>");
var containerHeight = $strip.parent().parent().height(); //a.k.a. 'mask' width
$strip.height(stripHeight);
var totalTravel = stripHeight;
var defTiming = totalTravel/settings.travelocity; // thanks to Scott Waye
function scrollnews(spazio, tempo){
$strip.animate({top: '-='+ spazio}, tempo, "linear", function(){$strip.css("top", containerHeight); scrollnews(totalTravel, defTiming);});
}
scrollnews(totalTravel, defTiming);
$strip.hover(function(){
jQuery(this).stop();
},
function(){
var offset = jQuery(this).offset();
var residualSpace = offset.top + stripHeight;
var residualTime = residualSpace/settings.travelocity;
scrollnews(residualSpace, residualTime);
});
});
};
$(function(){
$("ul#ticker01").liScroll();
});
【问题讨论】:
-
it just gets stuck in the middle and goes back to the start,- 是什么?if you give it a look it doesnt work properly- 为什么?它应该做什么?它做了什么?代码完全按照它编写的方式执行 - 所以说“不能正常工作”并不意味着代码是错误的,这意味着您将它用于错误的目的......“我在网上找到的脚本” - 什么当您找到该脚本时,您是否正在寻找?是什么让你认为别人的脚本做了你想做的事?您需要提供详细信息 -
好吧,我希望文本以一种平滑的方式一遍又一遍地滚动,它的作用是它只滚动一次,然后它到达列表的中间,然后跳到开头
标签: javascript jquery html scroll news-ticker