我有各种这样的代码:
$(function() {
$('#slider1').carouFredSel({
auto: false,
infinite:false,
circular:false,
prev:'#prev1',
next:'#next1',
pagination:"#pager1",
mousewheel:true,
swipe: {
onMouse: true,
onTouch: true
}
});
$('#slider2').carouFredSel({
auto: false,
infinite:false,
circular:false,
prev:'#prev2',
next:'#next2',
pagination:"#pager2",
mousewheel:true,
swipe: {
onMouse: true,
onTouch: true
}
});
});
window.addEvent('domready', function(){
var container = document.id('container'),
queuedElems = [];
var sorter = new Fx.Sort($$('#container .sort'), {
duration: '1000',
transition: Fx.Transitions.Back.easeInOut,
mode: 'vertical',
onComplete: function(){
displayDOM();
}
});
displayDOM();
document.id('swap').addEvent('click', function(event){
event.stop();
var elems = container.getChildren();
sorter.swap(elems[0], elems[elems.length - 1]);
});
window.addEvent('domready', function(){
var container = document.id('container2'),
queuedElems = [];
var sorter = new Fx.Sort($$('#container2 .sort'), {
duration: '1000',
transition: Fx.Transitions.Back.easeInOut,
mode: 'vertical',
onComplete: function(){
displayDOM();
}
});
displayDOM();
document.id('swap2').addEvent('click', function(event){
event.stop();
var elems = container.getChildren();
sorter.swap(elems[0], elems[elems.length - 1]);
});
我希望它们以“速记”方式编写,因为每次每个代码中的设置都是相同的,只有 ID 名称会发生变化(ID1、ID2 ...)。我不知道如何在 javascript 中执行此操作(仅在 css 中)。我唯一知道的是你需要'var'标签。
我猜任何有一点知识的人都可以轻松做到。我自己尝试了很多组合,但总是失败。一个例子会很好。它困难吗?