I learnt how to do jquery slide show in the early hours of today once I finish it felt like I had score a goal in the champion league final (refers about champion league was due to my love for football) . Thats how coding can feel you can gain so much joy out of it when you complete a task. For me it is not a job it is hobbie that i truely in joy.
Here is the code i did for my slide show using jquery
$(document).ready(function() {
var width=720;
var animationSpeed= 400;
var pause=3000;
var currentSlide=1;
var $slider = $('#slider');
var $sliderContainer = $slider.find('.slides');
var $slides =$sliderContainer.find('.slide');
var interval;
function startSlider(){
interval = setInterval(function(){
$sliderContainer.animate({'margin-left':'-='+width},animationSpeed,function(){
currentSlide++;
if (currentSlide==$slides.length ){
currentSlide=1;
$sliderContainer.css('margin-left',0);
}
});
},pause);
}
function stopSlider(){
clearInterval(interval);
}
$slider.on('mouseenter',stopSlider).on('mouseleave',startSlider );
startSlider();
});
No comments:
Post a Comment