jQuery: ¿Cómo puedo tener diferentes efectos en función de dónde se encuentra en la navegación

StackOverflow https://stackoverflow.com/questions/3754720

Pregunta

tengo esto:

$('#mask').cycle({ 
    fx: 'scrollLeft',
    timeout: 0, 
    speed:   300, 
    startingSlide: 0 
});

Sin embargo, hay un cierto caso en el que quiero que el fx sea scrollRight permite decir cuando (MyCondition == true)

¿cómo puedo hacer eso?

¿Fue útil?

Solución

Esto debería funcionar ..

(myCondition == true) ? _fx = "scrollLeft" : _fx = "scrollRight";

$('#mask').cycle({ 
    fx: _fx,
    timeout: 0, 
    speed:   300, 
    startingSlide: 0 
});

Sería más inteligente para hacer una función _fx(), aunque ..

function _fx(c) {
     return (c == true) ? "scrollLeft" : "scrollRight";
}

Otros consejos

Qué quiere decir esto:

var myFx = 'scrollLeft';
if( window.location.href.indexOf('myCondition=true') != -1 ) {
    myFx = 'scrollRight';
}

$('#mask').cycle({  
    fx: myFx,
    timeout: 0,  
    speed:   300,  
    startingSlide: 0  
}); 

Voy a salir en una extremidad y suponiendo que a desplazarse hacia la derecha se cambia a fx: scrollRight. En ese caso

if(myCondition == true) {
      $('#mask').cycle({
               fx: 'scrollRight',
               timeout: 0,
               speed: 300,
               startingSlide: 0
       });
} else {
      $('#mask').cycle({
               fx: 'scrollLeft',
               timeout: 0,
               speed: 300,
               startingSlide: 0
       });
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top