0
我試圖寫一個jQuery插件,做一些動畫,但我想在通過動畫選項類似於下面的字符串:jQuery的選項,以動畫
(function ($) {
$.fn.animateBox = function (options) {
options = $.extend({
animation: "backgroundColor: '#0E4839', padding: '10px', color: '#ffffff', fontSize: '153.846%', margin: '0 0 1em 0'"
}, options);
return $(this).each(function() {
var box = $(this);
box.animate({ options.animation }, 'slow');
});
};
})(jQuery);
這是可能的,因爲上面是目前拋出一個錯誤,抱怨在options.animation
點應該是一個分號(因爲它期望類似於backgroundColor: '#0E4839'
)
使動畫成爲一個對象而不是字符串。然後'box.animate(options.animation,'slow');' – Abhitalks
你爲什麼要把它作爲字符串傳遞而不是作爲對象 –
@abhitalks啊,太簡單了!如果您添加該答案,我將接受 – Pete