We have a generic slider functionality implemented in our product. We need to read the item index value from URL and scroll the slider to show the active item.
Following code logic is used to show the active thumbnail and for that i need to animate the DIV to negative left.
First, we get the total thumbnail items and then index of active item from URL Hash Value (i.e. #slide=7). One set contains minimum of 5 items. Need to multiply the slider width to the page set value where ActiveItemIndex lies.
Javascript Code -
showActiveThumbnailOnPageLoad : function() {
var _this = this,
totalThumbnails = $('.slidetabs a').length,
activeItem = window.location.href.split('=')[1],
scrollAmount;
if(activeItem > 5 && activeItem <= 10) {
scrollAmount = '-=' + 772
} else if(activeItem > 10 && activeItem <= 15) {
scrollAmount = '-=' + 772 * 2
} else if(activeItem > 15 && activeItem <= 20) {
scrollAmount = '-=' + 772 * 3
}
$('.slidetabs').stop().animate({
left : scrollAmount
});
}
As of now, hard code condition is used which support upto 20 items. Any help to make this code to support n number of items. I mean to say a generic code without hard code values.
Thanks in advance.