我正在尝试为特色滑块编写一个函数。
基本上,在一页上我希望旋转速度为 10000,而在另一页上我希望速度为 3000。
我分别拥有这两个功能 - 这很有效 - 但我知道会有一种更清洁/更好的方式来完成它而无需重复所有代码......
任何人都可以帮忙吗?
$(function(){
$("body.homePage #featured").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 10000, true);
$("body.homePage #featured").hover(
function() {
$("body.homePage #featured").tabs("rotate",0,true);
},
function() {
$("body.homePage #featured").tabs("rotate",10000,true);
}
);
});
$(function(){
$("body.boatDetailsPage #featured").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 3000, true);
$("body.boatDetailsPage #featured").hover(
function() {
$("body.boatDetailsPage #featured").tabs("rotate",0,true);
},
function() {
$("body.boatDetailsPage #featured").tabs("rotate",3000,true);
}
);
});
就像是
if ($('body').hasClass('homePage')) {
$("#featured").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 10000, true);
$("#featured").hover(
function() {
$("#featured").tabs("rotate",0,true);
},
function() {
$("#featured").tabs("rotate",10000,true);
}
);
} else {
$("#featured").tabs({fx:{opacity: "toggle"}}).tabs("rotate", 3000, true);
$("#featured").hover(
function() {
$("#featured").tabs("rotate",0,true);
},
function() {
$("#featured").tabs("rotate",3000,true);
}
);
}