这可能是一个愚蠢的问题,但我有一个问题不是代码无法运行 - 而是代码太长了......
一切正常,但例如有没有办法缩短if/else?或者是否可以使用更短的代码跟踪 4 个不同的var ?
var transitionState_N = '-';
var transitionState_X = '-';
var transitionState_Y = '-';
var transitionState_Z= '-';
// carousel 4way
function carousel_4way_N (n, el, m) {
var carousel = '#carousel-4way-nav-' + n
var carousel_content = '#carousel-4way-' + n
if (transitionState_N == '-')
{
transitionState_N = '+';
}
else
{
transitionState_N = '-';
}
$(carousel_reset).hide();
$(carousel).transition(
{y: m + '=10',delay:200}
);
};
function carousel_4way_X (n, el, m) {
var carousel = '#carousel-4way-nav-' + n
var carousel_content = '#carousel-4way-' + n
if (transitionState_X == '-')
{
transitionState_X = '+';
}
else
{
transitionState_X = '-';
}
$(carousel_reset).hide();
$(carousel).transition(
{y: m + '=10',delay:200}
);
};
function carousel_4way_Y (n, el, m) {
var carousel = '#carousel-4way-nav-' + n
var carousel_content = '#carousel-4way-' + n
if (transitionState_Y == '-')
{
transitionState_Y = '+';
}
else
{
transitionState_Y = '-';
}
$(carousel_reset).hide();
$(carousel).transition(
{y: m + '=10',delay:200}
);
};
function carousel_4way_Z (n, el, m) {
var carousel = '#carousel-4way-nav-' + n
var carousel_content = '#carousel-4way-' + n
if (transitionState_Z == '-')
{
transitionState_Z = '+';
}
else
{
transitionState_Z = '-';
}
$(carousel_reset).hide();
$(carousel).transition(
{y: m + '=10',delay:200}
);
};
$('#carousel-4way-nav-1').click(function(event){
$(carousel_reset_nav).not(this).transition(
{y:0});
return carousel_4way_N(1, this, (transitionState == '-') ? '+' : '-');
event.preventDefault();
});
$('#carousel-4way-nav-2').click(function(event){
$(carousel_reset_nav).not(this).transition(
{y:0});
return carousel_4way_X(2, this, (transitionState == '-') ? '+' : '-');
event.preventDefault();
});
$('#carousel-4way-nav-3').click(function(event){
$(carousel_reset_nav).not(this).transition(
{y:0});
return carousel_4way_Y(3, this, (transitionState == '-') ? '+' : '-');
event.preventDefault();
});
$('#carousel-4way-nav-4').click(function(event){
$(carousel_reset_nav).not(this).transition(
{y:0});
return carousel_4way_Z(4, this, (transitionState == '-') ? '+' : '-');
event.preventDefault();
});