Search code examples
jqueryloopsinfinity

jquery infinity loop to slide imagebar over and over


I want to make script to loop infinity so image will rotate everytime. This is my script which dont work:

function w_gore() {
  if(document.getElementById('mycarousel').style.top != '-544px' &&  document.getElementById('up').align == 'left') {
    document.getElementById('up').align = 'right';
    $("#mycarousel").animate({"top": "-=136px"}, "slow", function() {
        document.getElementById('up').align = 'left';
    }, setTimeout(function() {ruch();},1000));
  }
}

    function ruch() {
        w_gore();
    }

$(document).ready(function(){
    ruch();
});

Solution

  • You're already using jQuery, but not properly. Here are a few shortcuts:

    document.getElementById('mycarousel').style.top
    

    should be:

    $('#mycarousel').css('top')
    

    document.getElementById('up').align becomes $('#up').css('align')

    document.getElementById('up').align = 'right' becomes $('#up').css('align','right')

    You also need what Samich suggests.