jQuery: wie kann ich haben unterschiedliche Wirkungen auf, wo Sie in der Navigation sind
-
04-10-2019 - |
Frage
Ich habe diese:
$('#mask').cycle({
fx: 'scrollLeft',
timeout: 0,
speed: 300,
startingSlide: 0
});
Aber es gibt einen bestimmten Fall, in dem ich die fx sein will scrollRight können sagen, wenn (myCondition == true)
Wie kann ich das tun?
Lösung
Das sollte funktionieren ..
(myCondition == true) ? _fx = "scrollLeft" : _fx = "scrollRight";
$('#mask').cycle({
fx: _fx,
timeout: 0,
speed: 300,
startingSlide: 0
});
Es wäre klüger, eine _fx()
Funktion zu machen, obwohl ..
function _fx(c) {
return (c == true) ? "scrollLeft" : "scrollRight";
}
Andere Tipps
meinst du das:
var myFx = 'scrollLeft';
if( window.location.href.indexOf('myCondition=true') != -1 ) {
myFx = 'scrollRight';
}
$('#mask').cycle({
fx: myFx,
timeout: 0,
speed: 300,
startingSlide: 0
});
Ich gehe auf einem Bein und unter der Annahme, dass rechts scrollen Sie fx:
zu scrollRight ändern. In diesem Fall
if(myCondition == true) {
$('#mask').cycle({
fx: 'scrollRight',
timeout: 0,
speed: 300,
startingSlide: 0
});
} else {
$('#mask').cycle({
fx: 'scrollLeft',
timeout: 0,
speed: 300,
startingSlide: 0
});
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow