[jQuery] Jcarousel - Changing the starting position of the carousel according to the last page visited.
<div dir="ltr">Hi,
As the title says, i want to set the starting position of the jcarousel according to the last page visited.
What I've done so far is to decompose the last url with<b> document.referrer</b> and then process this String in order to set a value of a variable named <b>startingPosition</b>. Finally, in the <b>start</b> property of the configuration hash i set start: startingPosition.
The problem is that this is somehow a "slow" solution, since when I load the page where the carousel is, it starts by default in position 1, and then after the client does the algorithm of calculating the new position it then sets the starting point of the carousel where it should be. It's less than a second, but it does look bad, enough for not implementing it if I don't find a faster solution without jumps.
Please send me any ideas or suggestions. Don't consider me a pro with Javascript or Jquery please.
Thanks.
PS: I add the code I'm using right now (I'm adding it in the jquery.jcarousel.js file):
// Splits document.referrer
var reference = document.referrer.split('/');
// Initialize startingPosition to 1
var startingPosition = 1;
// Array with test I'm looking for in the referrer to select the starting position of the carousel
var listOfStringsImLookinFor = new Array();
listOfStringsImLookinFor[0] = "text1";
listOfStringsImLookinFor[1] = "text2";
listOfStringsImLookinFor[2] = "text3";
listOfStringsImLookinFor[3] = "text4";
// Calculates starting position
for(var i = 0; i < listOfStringsImLookinFor.length; i++)
for(var j = 0; j < reference.length; j++)
if(reference[j] == listOfStringsImLookinFor[i])
startingPosition = i + 1;
and then down in the carousel configuration: (hash defaults)
start: startingPosition,