看來,當我做兩次調用函數stockTicker()與獨立的DIV ID的 - 這兩個代號將無法流暢運行和跳躍: http://jsfiddle.net/Tb6VY/jQuery的動畫()與多個功能衝突調用
但是,如果我只有一個代碼可以正常工作: 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);
這是由於長度兩個字符串是不同的。 – sunleo
我正在檢查每個跨度的寬度,然後運行animate(),你對我能做些什麼來解決它有什麼建議嗎?我需要有可變長度... – mark1491
嘗試通過字符串的寬度來改變速度「right」:「+ =」+ $ width +「px」 duration:settings.speed * 200, – sunleo