Help me please. I want to optimize the slider code. The input to the s.displayRight function is the oBlock from s.showInfoRight. I want to submit two objects so that the 'left' direction is determined from the s.showInfoRight function (the object is direct). But the distance is not calculated and the slider freezes. Is it possible to do this at all?
function Services(sSelector){ var s = this; s.main = function(){ s.init(sSelector); s.link = s.find('.breadNav_link'); s.left = s.find('.arrow__left'); s.right = s.find('.arrow__right'); s.block = s.find('.services__block'); s.current = 0; s.max = s.block.length; sx = 2000; s.right.bind('click', s.showNext); s.left.bind('click', s.showPrev); s.link.bind('click', s.showInfo); } s.showNext = function(){ s.showInfoRight(+1); } s.showPrev = function(){ s.showInfoLeft(-1); } s.curObject = function(oCurrent){ var curObject = s.find('.services__block:eq(' + oCurrent + ')'); curObject.animate({opacity: 0}, 300, function(){ curObject.removeClass('services__block_active'); }); } s.length = function(oLength){ if(oLength >= s.max){ s.current = 0;} else if(oLength <0){ s.current = s.max -1;} } s.showInfoRight = function(iShift){ s.curObject(s.current); s.current+=iShift; s.length(s.current); s.displayRight((s.find('.services__block:eq(' + s.current + ')')), 'left'); } s.displayRight = function(oBlock, direct){ setTimeout(function(){ oBlock.stop().animate('{'+ direct + ': 2000}', 50, function(){ oBlock.addClass('services__block_active').css('opacity', 1); }); oBlock.animate({left: 0}, 900); }, 300); } s.showInfoLeft = function(iShift){ s.curObject(s.current); s.current+=iShift; s.length(s.current); s.displayLeft(s.find('.services__block:eq(' + s.current + ')') ); } s.displayLeft= function(oBlock){ setTimeout(function(){ oBlock.animate({right: 2000, left: -2000}, 50, function(){ oBlock.addClass('services__block_active').css('opacity', 1); }); oBlock.animate({right: 0, left:0}, 900); }, 300); }; $(document).ready(s.main); } Services.prototype = new Component();
animate({[direct]: 2000}- Grundy