3

I have a container with three divs of content inside of it. I am using javascript to navigate from left to right across the divs with the navigation tools referenced as an unordered list. Instead I would like to make those divs fixed and just move the entire container from left to right using the same navigation buttons.

Here is the javascript I tried. In order for this to work, I tried to change var $anchor = $(this) to var $anchor = $(the name of the container div), but that doesn't work. Could someone help me out with this? Thanks

<script type="text/javascript">
        $(function() {
            $('ul.nav a').bind('click',function(event){
                var $anchor = $(this);
                $('html, body').stop().animate({
                    scrollLeft: $($anchor.attr('href')).offset().left
                }, 1000);
                event.preventDefault();
            });
        });
 </script>
4

1 回答 1

2

谢谢...不过我找到了答案!

http://jsfiddle.net/pXy2C/

$(document).ready(function(){
$("#right").click(function(){
    $("#contents").animate({left:'-200px'},500);
    $("#container").animate({'margin-left':'200px'},500);
});
$("#left").click(function(){
    $("#contents").animate({left:'0px'},500);
     $("#container").animate({'margin-left':'0px'},500);
  });
 });
于 2013-02-13T17:44:10.083 回答