treehouse : what would you like to learn today?
Web Design Web Development iOS Development

[Solved] [SOLVED] JQuery - Autoslide Div

  • Can anyone point me in the right direction - I've got some jQuery code that basically moves a sliding image to the right.

    I'd like to it to automatically slide, can anyone tell me what code i need?





    <script type="text/javascript">
    (function($){

    //object containing margin settings
    var margins = {
    panel1: 0,
    panel2: -720,
    panel3: -1455,
    panel4: -2190,
    }

    //handle nav click
    $("#nav a").click(function(e){

    //stop browser default
    e.preventDefault();

    //remove on states for all nav links
    $("#nav a").removeClass("on");

    //add on state to selected nav link
    $(this).addClass("on");

    //set margin of slider to move
    $("#slider").animate({
    marginLeft: margins[$(this).attr("href").split("#")[1]]
    });
    });

    //hide descriptive text
    $("#slider p").hide();

    //show descriptive text on mouseover (hide on mouseout)
    $("#slider img").hover(
    function() {
    $(this).next().slideDown();
    }, function() {
    $(this).next().slideUp();
    });

    })(jQuery);
    </script>
  • Hey, have you got the html to go with this so I can throw it into jsFiddle and mess about with it?

    What you would need to do is write a function to move the slide to the next position
    then call this function in a setInterval();
  • Hi Mate, Thanks for helping me out:



    <div id="viewer">
    <div id="panels">
    <div id="slider">
    <div id="panel1">
    <img src="<?php bloginfo('template_url'); ?>/images/slider-2.png">
    </div>
    <div id="panel2">
    <img src="<?php bloginfo('template_url'); ?>/images/slider-4.png">

    </div>
    <div id="panel3">
    <img src="<?php bloginfo('template_url'); ?>/images/slider-1.png">
    </div>
    <div id="panel4">
    <img src="<?php bloginfo('template_url'); ?>/images/slider-3.png">
    </div>
    </div>
    </div>
    <ul id="nav">
    <li class="thumb2"><a href="#panel1"><img src="<?php bloginfo('template_url'); ?>/images/web-rhino.png" /></a></li>
    <li class="thumb4"><a href="#panel2"><img src="<?php bloginfo('template_url'); ?>/images/web-pelican.png" /></a></li>
    <li class="thumb1"><a href="#panel3"><img src="<?php bloginfo('template_url'); ?>/images/web-bee.png" /></a></li>
    <li class="thumb3"><a href="#panel4"><img src="<?php bloginfo('template_url'); ?>/images/web-weasel.png" /></a></li>
    </ul>
    </div>

  • Looks like I'd need your css too
    Can you update this http://jsfiddle.net/y7JD8/
    Then we can work on a function form what you have
  • Done mate. Thanks again.
  • Any luck mate?
  • Got a Link to your version?
  • Took a long look at that slider, it written entirely for click event, you would need to write a function that could automatically click the right button if you want to stick with this slider, otherwise unfortunately it would need to be rewritten
  • Thanks mate.