- This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
Viewing 5 posts - 1 through 5 (of 5 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Random div inside random div function
I am trying to create a function with fullpage.js that allows me to randomly move to another “article” when the video displayed inside the article is over.
For that I have to use the function “$ .fn.fullpage.moveTo (X, Y);”
X is the number of the section (the first one must begin with 1)
Y is the article number (the first one must start with 0)
Precisely, I would like to randomly choose a section (X), assign it the number that corresponds to it (with 1 as the first) and choose in this section an “article” randomly, depending on the number of articles (with 0 as the first) , and give him the number that corresponds to him (Y)
I managed to create a “random” function, but it just allows me to go to another “section”.
Here is my try on Jsfiddle which allows me to just choose a section starting with 1.
This should do the trick:
var numItems = $('section'),
random = Math.floor(Math.random()*numItems.length)+1,
chance = Math.floor(Math.random()*numItems.eq(random-1).find('article').length);
This function returns exactly the right numbers ! Thanks a lot, I appreciate your effort.
One last thing : I tried to integer it to the fullpage function but it doesn’t work, I tried :
$.fn.fullpage.moveTo(random + ‘, ‘ + chance);
$.fn.fullpage.moveTo(random, chance);
This is not working..
And I simply need to declare $ .fn.fullpage.moveTo (X, Y);
Sorry, my fault, I didn’t copied the right code.
Thank you very much, have a good week !!
Same to you, glad it worked.