javascript - jquery move elements into a random order -


I am trying to display a series of images in random order. However, as long as all the items are shown, I do not want to repeat any single item, instead of choosing a random image from the array, I want to move the entire array, make it random, and then Already in the sequence, the final element here is my code:

HTML:

  & lt; Div id = "tout4" & lt; Img src = "picture / gallery 01.jpg" class = "img_lg" /> & Lt; Img src = "picture / gallery 02.jpg" class = "img_lg" /> & Lt; Img src = "picture / gallery 03.jpg" class = "img_lg" /> & Lt; / Div & gt;   

and JavaScript, which currently selects and displays items in order:

  var gallery lang = $ ('# tout4 img.img_lg' ). Length ; Var currentGallery = 0; Set Interval (Chakra Gallery, 5000); Function Cycle Gallery () {$ ('# tout4 img.img_lg'). Eq (current gallery) .FadeOut (300); If (Current Gallery & lt; (Gallery Leng-1)) {currentGallery ++; } And {currentGallery = 0; } $ ('# Tout4 img.img_lg'). Eq (current gallery). FadeIn (300); }   

So how can I rearrange the actual sequence of images, and not only for whom has been chosen for that sequence?

After a lot of exploration, I decided to take fisherman's algorithm and without the need for cloning it Implemented on jquery

  $ ('# Tout4 img.img_lg'). Shuffle (); / * * Simplified jQuery array of elements - Fisher-Yets algorithm * / jQuery.fn.shuffle = function () {var j; For (var i = 0; i & lt; this.length; i ++) {j = Math.flur (Math.Random (*) * this.length); Before $ (this [i]) ($ (this [j])). } Return it; };    

Comments