【问题标题】:Jquery slider modification?jQuery滑块修改?
【发布时间】:2014-06-19 14:57:05
【问题描述】:

嗨,我有一个 jquery 滑块的示例代码,它包含 3 个 div 幻灯片。 它工作得很好,但我在同一个滑块中也需要 3 个donts(小圆圈)。 谁能帮帮我,如何添加这些。

我现在拥有的是

我想要的是相同的滑块,但我也想要代表每个滑块的 3 个点,当我们单击点时它应该打开相应的滑块。

我的代码

    <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
  <script type="text/javascript">
$("#slideshow > div:gt(0)").hide();

setInterval(function() { 
  $('#slideshow > div:first')
    .fadeOut(1000)
    .next()
    .fadeIn(1000)
    .end()
    .appendTo('#slideshow');
},  3000);
  </script>
</head>

<body>
<style>
#slider_one_img{
  float: left;
  background-image: url('one.jpg');
  width: 84px;
height: 86px;
}
#slider_two_img{
float: left;
background-image: url('two.png');
  width: 84px;
height: 86px;
}
#slider_three_img{
  float: left;
  background-image: url('three.jpg');
  width: 84px;
height: 86px;
}
#slider_one_text{

  width:70%;
  text-align: left;
  margin-top: 3%;
  float: left;

}

#slideshow { 
    margin: 68px auto; 
    position: relative; 
    width: 68%; 
    height: 120px; 
    padding: 10px; 
    box-shadow: 0 0 20px rgba(0,0,0,0.4); 
    margin-left: 2%;
}

#slideshow > div { 
    position: absolute; 
    top: 10px; 
    left: 10px; 
    right: 10px; 
    bottom: 10px; 
}
</style>
<div id="slideshow">
   <div>
     <div id="slider_one_text">My first text</div>
     <div id="slider_one_img"></div>
   </div>
   <div>
      <div id="slider_one_text">My second text...erewrew.r.ewr.eqwr.ewrweqrqewrqwerwerwer
</div>
     <div id="slider_two_img"></div>
   </div>
   <div>
      <div id="slider_one_text">My third text skjsndgnsdkjgndnskgnksngk</div>
     <div id="slider_three_img"></div>
   </div>
</div>
</body>
</html>

【问题讨论】:

    标签: javascript jquery html css slider


    【解决方案1】:

    你可以这样做作为一个例子

    http://jsfiddle.net/danhayman/yxnet/

    jQuery:

        $("#dot-wrapper div").click(function(){
        var index = $(this).index();
        $("#dot-wrapper div").removeClass("current").eq(index).addClass("current");
        $("#image-wrapper div").removeClass("current").eq(index).addClass("current");
        })
    

    CSS:

    #image-wrapper div{
        width: 10em;
        height: 10em;
        display: none;
    }
    
    #image-wrapper .current{
        display: block;
    }
    
    #image-wrapper div:nth-child(1){
       background-color:red; 
    }
    
    #image-wrapper div:nth-child(2){
       background-color:green; 
    } 
    
    #image-wrapper div:nth-child(3){
       background-color:blue; 
    } 
    
    #dot-wrapper div{
        width: 1em;
        height: 1em;
        border-radius: .5em;
        background-color: gray;
        display: inline-block;
        cursor: pointer;
        margin: .5em;
    }
    
    #dot-wrapper .current{
        background-color: black;
    }
    

    HTML:

    <div id="image-wrapper">
        <div class="current"></div>
        <div></div>
        <div></div>
    </div>
    
    <div id="dot-wrapper">
        <div class="current"></div>
        <div></div>
        <div></div>
    </div>
    

    【讨论】:

      猜你喜欢
      • 2011-04-12
      • 2013-11-09
      • 1970-01-01
      • 1970-01-01
      • 2011-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多