似乎当我使用单独的 div ID 对函数 stockTicker() 进行两次调用时 - 这两个代码不会顺利运行并跳来跳去:http: //jsfiddle.net/Tb6VY/
但是,如果我只有一个代码,它就可以正常工作:http: //jsfiddle.net/39JJ4/
关于如何让第一个工作的任何想法?
功能:
( function($) {
$.fn.stockTicker = function(options) {
if (typeof (options) == 'undefined') {
options = {};
}
var settings = $.extend( {}, $.fn.stockTicker.defaults, options);
var $ticker = $(this);
function startTicker() {
//stopTicker();
$firstElem = $ticker.children(":first");
var $width = $firstElem.width();
$ticker.stop().animate({
"right": "+="+$width+"px"
}, {
duration: settings.speed*200,
easing: 'linear',
complete: function() {
$ticker.css({"right": "-="+($width)+"px"});
$firstElem.clone().appendTo($ticker);
$firstElem.remove();
startTicker();
}
});
}
function stopTicker() {
$ticker.stop();
}
$ticker.hover(stopTicker, startTicker);
startTicker();
};
$.fn.stockTicker.settings = {};
$.fn.stockTicker.defaults = {
tickerID :null,
speed :1,
};
})(jQuery);