-1

I have added a slider to my site but it seems to only run once. It stops on 2nd image. I want it to keep sliding every 5 seconds. Please help me!

Source: http://codepen.io/zuraizm/pen/vGDHl

Javascript:

var slideCount = $('#slider ul li').length;
var slideWidth = $('#slider ul li').width();
var slideHeight = $('#slider ul li').height();
var sliderUlWidth = slideCount * slideWidth;

$('#slider').css({ width: slideWidth, height: slideHeight });

$('#slider ul').css({ width: sliderUlWidth, marginLeft: - slideWidth });

$('#slider ul li:last-child').prependTo('#slider ul');

function moveLeft() {
    $('#slider ul').animate({
        left: + slideWidth
    }, 200, function () {
        $('#slider ul li:last-child').prependTo('#slider ul');
        $('#slider ul').css('left', '');
    });
};

function moveRight() {
    $('#slider ul').animate({
        left: - slideWidth
    }, 200, function () {
        $('#slider ul li:first-child').appendTo('#slider ul');
        $('#slider ul').css('left', '');
    });
};


$('a.control_prev').click(function () {
    moveLeft();
});

$('a.control_next').click(function () {
    moveRight();
});

$(function(){
setInterval(function () {
    moveRight();
}, 5000);
});
Stefan
  • 61
  • 9

1 Answers1

0

find and update your code with:

remove checkbox function "$('#checkbox').change(function() ... " or just replace with

setInterval(function () {
      moveRight();
  }, 5000);  

that'll fix it.

codepen

Demo

krozero
  • 5,929
  • 3
  • 21
  • 33
  • But then it doesn't slide automaticly. I need it to slide automaticly every 5 seconds. How can i do that? – Stefan Apr 20 '14 at 17:10
  • what do you mean "it doesn't slide automaticly"? did you mean auto sliding without clicking checkbox? – krozero Apr 20 '14 at 17:15
  • currently auto slide works fine when you click checkbox. http://codepen.io/kzkpro/full/aHALy – krozero Apr 20 '14 at 17:16
  • I mean that i want to remove the checkbox. It should slide automaticly without any checkbox. – Stefan Apr 20 '14 at 17:27
  • It still doesn't work. I really don't understand why. It only slides one time. Then it stops. I can still use the buttons right and left to slide tho. – Stefan Apr 20 '14 at 21:00
  • weird! which browser are you using? it works fine with chrome(slides in every five seconds). – krozero Apr 21 '14 at 05:29
  • also working fine in firefox and IE 11. may be something wrong with your system!!! – krozero Apr 21 '14 at 05:32