Reputation: 455
I have got "slides" div and "slidecontrols" div. slidecontrols div contains thumbnail and title of slides and it's displaying title and raising opacity when activate one slide.
slides and slidecontrols are in array on javascript and appending to page with jquery.
I need to randomize sorting of slides every page refresh but when randomizing slides and slidecontrols there is problem appears..
think like :
slides : 1, 2, 3, 4, 5
slidecontrols : 1a, 2a, 3a, 4a, 5a
after randomizing :
slides : 3, 2, 1, 5, 4
slidecontrols : 4a, 2a, 5a, 1a, 3a
but I want this sorting after randomizing :
slides : 3, 2, 1, 5, 4
slidecontrols : 3a, 2a, 1a, 5a, 4a
Upvotes: 1
Views: 127
Reputation: 12395
Try this, though there are some temp variabls
var a = [1, 2, 3, 4, 5];
var b = ['1a', '2a', '3a', '4a', '5a'];
var temp = [];
var i = 0;
a.sort(function() { return temp[temp.length] = (Math.random() - 0.5); });
b.sort(function() { return temp[i++]; });
Upvotes: 1
Reputation: 24534
You don´t have to randomize both. You have to randomize the slides and then sync the slidecontrols with them instead ;)
Upvotes: 2