Can I make this auto scroll?

Discussion in 'JavaScript' started by m0rt1l, Jun 6, 2012.

  1. #1
    I have a piece of code from my image scroller. You drag the handle and the images slide from right to left. Is there anyway I can make this auto scoll?

    $(document).ready(function()
    {
    $('.button').attr('data-show', '0');
    $('.items').wrapInner("<table><tr>");
    $('.items .item').wrap("<td></td>");

    $('.button').click(function()
    {
    $(this).attr('data-show', $(this).attr('data-show') == '0' ? '1' : '0');

    var show = ($(this).attr('data-show') == '1');
    var eItem = $(this).parent('.image').parent('.item');

    $(this).text(show ? 'Close' : 'More Details');
    eItem.animate({width: show ? '400px' : '200px'}, 400);
    eItem.children('.image').animate({left: show ? '200px' : '0px'},
    400, function()
    {
    eItem.children('.info').css('display', show ? 'block' : 'none');
    });
    });

    $('.handle').draggable({
    containment: '.bar',
    drag: function(event, ui)
    {
    var full = $('.bar').width() - $(this).width();
    var position = ui.position.left / full;

    position *= ($('.items').children('table').width() - $('.itemWrap').width());
    $('.itemWrap').scrollLeft(position);
    }
    });

    document.onselectstart = function() {
    return false;
    };
    });

    Thanks
     
    m0rt1l, Jun 6, 2012 IP
  2. Unni krishnan

    Unni krishnan Peon

    Messages:
    237
    Likes Received:
    9
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Instead of calling this on draggable event, you can use setInterval function to repeat the scroll effect at regular intervals.
     
    Unni krishnan, Jun 27, 2012 IP