我有這些「功能」在塊中重複的各種元素。 如何簡化使用「var」?簡化函數jquery
謝謝:)
例如:
$('#test1').waypoint(function (direction) {
if (direction === 'down') {
$(this).addClass("here");
$(this).prevAll().removeClass("here");
$(this).prev().prev().addClass("here_pre");
$(this).next().next().addClass("here_pre");
},
});
我想在像這樣的一個解決辦法:
var active_here = $(this).addClass("here"),
$(this).prevAll().removeClass("here"),
$(this).prev().prev().addClass("here_pre"),
$(this).next().next().addClass("here_pre");
最後記得是這樣的:
$('#test1').waypoint(function (direction) {
if (direction === 'down') {
active_here;
},
});
$('#test2').waypoint(function (direction) {
if (direction === 'up') {
active_here;
},
});
etc... etc... etc...
你問如何編寫自己的功能? – SLaks 2015-04-06 02:22:07