【问题标题】:Button click show den div hide prev div like slider按钮单击 show den div 隐藏 prev div 像滑块
【发布时间】:2014-10-12 20:40:44
【问题描述】:

您好,我想在单击按钮时创建类似滑块的东西,显示下一个 div 并用 3 个 div 隐藏上一个 div。

HTML:

<a href="#"><i class="fa fa-chevron-left"></i></a>
<a href="#"><i class="fa fa-chevron-right"></i></a>
<div class="divs">
    <div>1</div>
    <div> 2</div>
    <div> 3</div>
</div>

jQuery:

$(document).ready(function () {      
    $(".fa-chevron-right").click(function (e) {});
    $(".fa-chevron-left").click(function (e) {});
});

【问题讨论】:

标签: javascript jquery css function onclick


【解决方案1】:

您可以使用 jQuery 的 next()prev()siblings() 方法轻松完成它。我花了五分钟写了一些粗略的代码。

http://jsfiddle.net/85kcffo9/1/

希望它对您学习 jQuery 有所帮助。

【讨论】:

    【解决方案2】:
        <html>
        <body>
    
        <head>
       <style>
        .divControl
       {
           position:absolute;
           width: 80px;
           height: 80px;
           -webkit-border-radius: 20px;
           -moz-border-radius: 20px;
            border-radius: 20px;
        }
        </style>
       </head>
       <a href="#"><i class="fa fa-chevron-left">left</i></a>
       <a href="#"><i class="fa fa-chevron-right">right</i></a>
       <div class="divs"        
    style="position:absolute;width:250px;height:80px;overflow:hidden;border: 3px #658958    solid;">
        <div id="wrapper" style="position:absolute;width:100%;height:100%;left:0px;top:0px;">
        <div class="divControl" style="left:0px;background:red">1</div>
        <div class="divControl" style="left:100px;background:blue"> 2</div>
        <div class="divControl" style="left:200px;background:green"> 3</div>
        </div>
        </div>
    
    
        <script>
    
          $(document).ready(function () {      
           $(".fa-chevron-right").click(function (e) {
    
           $( "#wrapper" ).animate({
           left: "+=70",
           opacity: 1
           }, 700 ); 
    
          });
          $(".fa-chevron-left").click(function (e) {
    
         $( "#wrapper" ).animate({
         left: "-=70",
         opacity: 1
        }, 700 );    
    
        });
         });
         </script>
    
         </body>
        </html>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-06-14
      • 2013-04-05
      • 1970-01-01
      • 2016-05-21
      • 2013-01-16
      • 1970-01-01
      • 1970-01-01
      • 2014-11-04
      相关资源
      最近更新 更多