我是新手,我不知道如何编写插件。任何人都可以帮助如何为这个jquery函数编写插件。
$(document).ready(function(){
var offset_1 = $("li.list:first-child").position().left;
var offset_2 = $("li.list:nth-child(2)").position().left;
var totalWidth =offset_2-offset_1;
$("a.abc").click(function() {
$("#scroller").not(":animated").animate({"scrollLeft":"-="+totalWidth},300);
return false;
});
$("a.def").click(function() {
$("#scroller").not(":animated").animate({"scrollLeft":"+="+totalWidth},300);
return false;
});
});
答案 0 :(得分:0)
你应该知道它是如何工作的。设计人们使用你的插件的方式。
样本(只是一个想法)
$('.target').doSomething({
offset1 : 'li.list:first-child',
offset2 : 'li.list:nth-child(2)',
toLeft : 'a.abc',
toRight : 'a.def'
})
(function($){
$.fn.doSomething = function(options){
var offset1 = $(options.offset1).position.left;
var offset2 = $(options.offset2).position.left;
var toLeft = $(options.toLeft);
//... do something
}
}).(jQuery)