JohnA
JohnA

Reputation: 1913

Randomize a value in jQuery

That slider FancyTransitions does not support random effects. So to work around that I need the value for effect: 'curtain' to be random either which can be "curtain", "zipper", or "wave". Unless there's a better work around.

<script type="text/javascript">
    $(document).ready( function(){
        $('#slideshowHolder').jqFancyTransitions({
        width: 500, // width of panel
        height: 333, // height of panel
        strips: 10, // number of strips
        delay: 4000, // delay between images in ms
        stripDelay: 50, // delay beetwen strips in ms
        titleOpacity: 0.7, // opacity of title
        titleSpeed: 1000, // speed of title appereance in ms
        position: 'alternate', // top, bottom, alternate, curtain
        direction: 'random', // left, right, alternate, random, fountain, fountainAlternate
        effect: 'curtain', // curtain, zipper, wave
        navigation: false, // prev next and buttons
        links : false // show images as links                                                   });
    });
</script>

Upvotes: 1

Views: 446

Answers (4)

Varol
Varol

Reputation: 1858

plugin doesn't have a callback for transitions so you need to modify it to allow randomizing the effect parameter.

adding params.effect = ['curtain', 'zipper', 'wave'][Math.floor(Math.random() * 3)]; to the top of the $.transition function in plugin code would randomly set the effect parameter on each transition. not tested but this should be the way.

i strongly recommend using a better slideshow plugin like cycle or nivo-slider though.

Upvotes: 0

Jason
Jason

Reputation: 52523

var effects = ["curtain", "zipper", "wave"];

$(document).ready( function(){
    $('#slideshowHolder').jqFancyTransitions({
    ...
    effect: effects[Math.floor(Math.random() * 3)], // curtain, zipper, wave
    ...
    });
});

Upvotes: 0

Mark Rawlingson
Mark Rawlingson

Reputation: 148

Try something like...

var effect;
var i = Math.floor((Math.random()*3)+1);

if (i==1) effect = "curtain";
if (i==2) effect = "zipper";
if (i==3) effect = "wave";

Upvotes: 0

Imp
Imp

Reputation: 8609

Do you mean

effect: ['curtain', 'zipper', 'wave'][Math.floor(Math.random() * 3)] 

?

Upvotes: 1

Related Questions