I have following code for a content scroller. This has been implemented with basic jquery. Iam trying to convert the same using advanced javascript concepts. Guide me to implement the same.
Working Code :
$(document).ready(function() {
var currentPosition = 0,
slideWidth = 112,
slides = $('#scroller ul li'),
numberOfSlides = slides.length;
scrollerContainer = $('#scroller ul');
$(scrollerContainer).css('width', slideWidth * numberOfSlides);
manageControls(currentPosition);
$('.control').click(function(){
currentPosition = ($(this).attr('id')=='rightControl') ? currentPosition+1 : currentPosition-1;
manageControls(currentPosition);
$(scrollerContainer).animate({
'marginLeft' : slideWidth*(-(currentPosition*3))
});
});
function manageControls(position){
if(position==0){ $('#leftControl').hide() }
else{ $('#leftControl').show() }
if((position*3)==numberOfSlides-1 || (position*3)==numberOfSlides-3 || (position*3)==numberOfSlides-2) { $('#rightControl').hide() }
else{ $('#rightControl').show() }
}
});
Advanced Code Structure : Initial understanding
if(!scroller) { var scroller = {}; }
scroller =
{
videos : {
moveThumbnails : function() {
},
gotonextThumbnails : function() {
var obj = this;
},
gotopreviousThumbnails : function() {
var obj = this;
},
init : function() {
var obj = this;
}
},
init : function() {
var obj = this;
this.videos.init();
}
}
Working example : http://jsfiddle.net/ylokesh/9EyEu/