请问像这样的js实现滑动条滑动上面的div里内容相应显示,这功能怎么实现呢
就是滑动到第一个时就显示第一页内容,滑动到第二格里,上面的div就显示第二页内容,谢谢
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<div id="Move_obj" style="width:200px; height:200px; background:#CCC;">
     <div id="Move_1">第一页内容</div>
     <div style="display:none">第二页内容</div>
     <div style="display:none">第三页内容</div>
     <div style="display:none">第四页内容</div>
     <div style="display:none">第五页内容</div>
     <div style="display:none">第六页内容</div>
</div>
<img src="http://img.bbs.csdn.net/upload/201308/03/1375511598_985974.jpg" width="184" height="26" />
</body>
</html>滑动条

解决方案 »

  1.   

    没注意到这样的效果,只是现在公司想要弄出来
    其实应该跟TAB切换相似,默认显示是第一个,但是下面的滑动条滑动第二格里,上面的内容就显示第二页的内容,第一页内容肯定是隐藏起来了,
    就是同一个位置,根据下面的滑动条位置移动,上面的div里显示不同的内容
      

  2.   

    丢人了原来是这玩:http://www.cnblogs.com/cloudgamer/archive/2008/12/24/1360988.html可以用百分比或是坐标来判断该显示哪个content
      

  3.   

    简单写了写:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <title>无标题文档</title>
    <style type="text/css">
    #Move_obj{width:100%; height:200px; background:#CCC;overflow:hidden;}
    .blk{display:none;width:90%;line-height:200px;height:200px;background-color:#ddd;text-align:center;}
    .focus{display:block;}
    .barcon{width:100%;height:30px;padding:5px 0;border:1px solid #ddd;position:relative;}
    .barcon span{display:inline-block;width:100px;height:30px;background-color:#999900;position:absolute;left:0;}
    </style>
    </head><body>
    <div id="Move_obj">
         <div class="blk focus">第一页内容</div>
         <div class="blk" style="display:none">第二页内容</div>
         <div class="blk" style="display:none">第三页内容</div>
         <div class="blk" style="display:none">第四页内容</div>
         <div class="blk" style="display:none">第五页内容</div>
    </div><div class="barcon">
    <span>&nbsp;</span>
    </div>
    <script type="text/javascript">
    jQuery(function($){
    $('.barcon').click(function(e){
    //获取barcon的总长度
    var tl=parseInt($(this).css('width'));
    //获取当前事件的坐标
    var ex=e.pageX;
    //计算当前在哪个段位
    var elimit=parseInt(tl / 5);
    //计算是显示哪个tab
    var eindex=parseInt(ex / elimit);
    //把bar移动到指定的位置上
    //是否超过了tl

    $(this).find('span').css({left:(parseInt(ex)>=tl)?tl-100:ex+'px'});

    $('.blk').eq(eindex).show(function(){//{display:'block'});
    $('.blk.focus').removeClass('focus').hide();
    $(this).addClass('focus');
    });

    });
    });
    </script>
    </body>
    </html>还有点小问题留着你修复了
      

  4.   

    修正版本:<script type="text/javascript">
    jQuery(function($){
    $('.barcon').click(function(e){
    //获取barcon的总长度
    var tl=parseInt($(this).css('width'));
    //获取当前事件的坐标
    var ex=e.pageX;
    //计算当前在哪个段位
    var elimit=parseInt(tl / 5);
    //计算是显示哪个tab
    var eindex=parseInt(ex / elimit);
    //把bar移动到指定的位置上
    //是否超过了tl
    $(this).find('span').css({left:(parseInt(ex)>=tl)?tl-100:ex+'px'}).html(eindex);
    if(eindex == $('.blk').index($('.focus'))) return;
    $('.blk').eq(eindex).show(function(){
    $('.blk.focus').removeClass('focus').hide();
    $(this).addClass('focus');
    });
    });
    });
    </script>
      

  5.   

    你好街头小贩,今天又测试了下,有点问题麻烦能帮我下吗,对这个还是不懂,谢谢
    滑动块上面的第一个默认为1,后台拖动跟上面的内容总是不一致,向前时特别到第一个位置是点击都是显示零,最好在把后右的(1/6)这边能够根据拖动改变1的值
    非常感谢。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <title>无标题文档</title>
    <style type="text/css">
    body,html{margin:0; padding:0px; font-size:12px; color:#fff;  background:#303438; }
    #Move_obj{width:190px; height:200px; background:#CCC;overflow:hidden;}
    .blk{display:none;line-height:200px;height:200px;background-color:#ddd;text-align:center;}
    .focus{display:block;}
    .barcon{width:150px;height:20px;position:relative; background:#FF0;display:-moz-inline-box; display:inline-block; float:left; }
    .barcon span{width:25px;height:20px;background-color:#999900;position:absolute;left:0;cursor:pointer;display:-moz-inline-box; display:inline-block; text-align:center }
    .cc { height:20px; line-height:20px; text-align:center; background:#969;}
    </style>
    </head>
    <body>
    <div id="Move_obj">
         <div class="blk focus">第一页内容</div>
         <div class="blk" style="display:none">第二页内容</div>
         <div class="blk" style="display:none">第三页内容</div>
         <div class="blk" style="display:none">第四页内容</div>
         <div class="blk" style="display:none">第五页内容</div>
         <div class="blk" style="display:none">第六页内容</div>
    </div>
    <div style="width:190px">
        <div class="barcon">
            <span>&nbsp;</span>
        </div>
        <div class="cc">1/6</div>
    </div>
    <script type="text/javascript">
        jQuery(function($){
            $('.barcon').click(function(e){
                //获取barcon的总长度
                var tl=parseInt($(this).css('width'));
                //获取当前事件的坐标
                var ex=e.pageX;
                //计算当前在哪个段位
                var elimit=parseInt(tl / 6);
                //计算是显示哪个tab
                var eindex=parseInt(ex / elimit);
                //把bar移动到指定的位置上
                //是否超过了tl
                $(this).find('span').css({left:(parseInt(ex)>=tl)?tl-25:ex+'px'}).html(eindex);
                if(eindex == $('.blk').index($('.focus'))) return;
                $('.blk').eq(eindex).show(function(){
                    $('.blk.focus').removeClass('focus').hide();
                    $(this).addClass('focus');
                });
            });
        });
    </script>
    </body>
    </html>
      

  6.   

    朋友们,上面的代码是街头小贩版主帮我写的,但是还有点问题,麻烦有空的朋友帮我完善下吧,谢谢滑动块上面的第一个默认为1,后台拖动跟上面的内容总是不一致,向前时特别到第一个位置是点击都是显示零,最好在把后右的(1/6)这边能够根据拖动改变1的值
    非常感谢。
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
    <title>无标题文档</title>
    <style type="text/css">
    body,html{margin:0; padding:0px; font-size:12px; color:#fff;  background:#303438; }
    #Move_obj{width:190px; height:200px; background:#CCC;overflow:hidden;}
    .blk{display:none;line-height:200px;height:200px;background-color:#ddd;text-align:center;}
    .focus{display:block;}
    .barcon{width:150px;height:20px;position:relative; background:#FF0;display:-moz-inline-box; display:inline-block; float:left; }
    .barcon span{width:25px;height:20px;background-color:#999900;position:absolute;left:0;cursor:pointer;display:-moz-inline-box; display:inline-block; text-align:center }
    .cc { height:20px; line-height:20px; text-align:center; background:#969;}
    </style>
    </head>
    <body>
    <div id="Move_obj">
         <div class="blk focus">第一页内容</div>
         <div class="blk" style="display:none">第二页内容</div>
         <div class="blk" style="display:none">第三页内容</div>
         <div class="blk" style="display:none">第四页内容</div>
         <div class="blk" style="display:none">第五页内容</div>
         <div class="blk" style="display:none">第六页内容</div>
    </div>
    <div style="width:190px">
        <div class="barcon">
            <span>&nbsp;</span>
        </div>
        <div class="cc">1/6</div>
    </div>
    <script type="text/javascript">
        jQuery(function($){
            $('.barcon').click(function(e){
                //获取barcon的总长度
                var tl=parseInt($(this).css('width'));
                //获取当前事件的坐标
                var ex=e.pageX;
                //计算当前在哪个段位
                var elimit=parseInt(tl / 6);
                //计算是显示哪个tab
                var eindex=parseInt(ex / elimit);
                //把bar移动到指定的位置上
                //是否超过了tl
                $(this).find('span').css({left:(parseInt(ex)>=tl)?tl-25:ex+'px'}).html(eindex);
                if(eindex == $('.blk').index($('.focus'))) return;
                $('.blk').eq(eindex).show(function(){
                    $('.blk.focus').removeClass('focus').hide();
                    $(this).addClass('focus');
                });
            });
        });
    </script>
    </body>
    </html>