如何使用轮播隐藏和显示背景图像?

凯文

我真的是j查询的新手。这可能会很尴尬,但是我很难找到如何使用完整背景图像创建滑块图像轮播的方法。我看过其他解决方案,但是似乎您必须将要滑动的所有图片的大小都固定为宽度(例如div宽度为9000px)。但是,我觉得我可以使用某种类型的数组或索引函数,在其中可以使用循环来迭代某些东西以隐藏和显示。从基本的javascript到jquery的过渡是我在调整时遇到的麻烦。如果有人可以给我一些建议或技巧,那将是很好的。这是我的下面的代码。谢谢

http://codepen.io/kevk87/pen/PPNPmg

    <main>

<div class="container">
<ul>  
  <li class="one"> 
  </li>
  <li class="two"> </li>
  <li class="three"></li>
  <li class="four"></li>
</ul>

  <div class="nav">
      <ul >
       <li class="first active"> </li>
      <li class="second"> </li>
       <li class="third"> </li>
      <li class="fourth"> </li>
      </ul>
  </div>
</div>
</ul>
</main>

的CSS

*{
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}



ul {
  list-style:none;
  height:100%;
}
main, html, body{
  height:100%;
}

.container {
  height:100%;
  postion:relative;

}

.one {  
   height:100%;   background:url(http://hamderser.dk/blog/images/clairvoyant/clairvoyant-nature-nature2.jpg) center center no-repeat fixed; 
   background-size:cover;

}  

.two {
  background: url(http://www.atilaminates.com/wp-content/uploads/2015/05/nature-wlk.jpeg) center center no-repeat fixed;
  height:100%; 
}
.three {
  background: url(http://php.drishinfo.com/photostudioone/wp-content/uploads/2014/11/nature-wallpaper-hd-1920x1080.jpg) center center no-repeat fixed;
  height:100%; 
}
.four {
  background: url(http://www.projecthappyhearts.com/wp-content/uploads/2015/04/green-nature-dual-monitor-other.jpg) center center no-repeat fixed;
  height:100%; 
}


.nav ul li {
  width:20px;
  background-color:white;
  height:20px;
  display:inline-block;
  margin-right:20px; 
}
.nav ul li:last-child {
  margin-right:0px;
}

.nav {
  position: absolute;
  bottom:100px;
  left:50%;
  transform:translate(-50%,-50%);
}

.nav ul .active{
  background-color:black;
}

.two, .three, .four {
  display:none;
}

Java脚本

//change active class

    $('.nav ul').click(function(){
  $(this).removeClass('active');  
    $(this).addClass('active');
});

//Click handlers to change image and active class


$('.first').click(function(){
    $('.one').show();
  $('.two').hide();
  $('.three').hide();
  $('.four').hide();
});


$('.second').click(function(){
    $('.two').show();
  $('.one').hide();
  $('.three').hide();
  $('.four').hide();
});

$('.third').click(function(){
    $('.three').show();
  $('.one').hide();
  $('.two').hide();
  $('.four').hide();
});

$('.fourth').click(function(){
    $('.four').show();
  $('.one').hide();
  $('.three').hide();
  $('.two').hide();
});
迪诺·米特

干得好。使用jquery函数的精美版本和简化版本。

http://jsfiddle.net/7erakxad/

  <main>

<div class="container">
<ul>  
  <li class="one"> 
  </li>
  <li class="two"> </li>
  <li class="three"></li>
  <li class="four"></li>
</ul>

  <div class="nav">
      <ul >
       <li class="first active"> </li>
      <li class="second"> </li>
       <li class="third"> </li>
      <li class="fourth"> </li>
      </ul>
  </div>
</div>
</ul>
</main>


 <script>
  $(".nav > ul li").click(function () {
        $('.nav > ul li').each(function () {
            $(this).removeClass('active');       
        });
        var index = $(this).index();
        $(".container > ul").find("li").each(function (i2) {
            if (index == $(this).index())
                $(this).show();
            else
                $(this).hide();
        });
        $(this).addClass('active');
    });



 </script>

   <style>
*{
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}



ul {
  list-style:none;
  height:100%;
}
main, html, body{
  height:100%;
}

.container {
  height:100%;
  postion:relative;

}

.one {  
   height:100%;   background:url(http://hamderser.dk/blog/images/clairvoyant/clairvoyant-nature-nature2.jpg) center center no-repeat fixed; 
   background-size:cover;

}  

.two {
  background: url(http://www.atilaminates.com/wp-content/uploads/2015/05/nature-wlk.jpeg) center center no-repeat fixed;
  height:100%; 
}
.three {
  background: url(http://php.drishinfo.com/photostudioone/wp-content/uploads/2014/11/nature-wallpaper-hd-1920x1080.jpg) center center no-repeat fixed;
  height:100%; 
}
.four {
  background: url(http://www.projecthappyhearts.com/wp-content/uploads/2015/04/green-nature-dual-monitor-other.jpg) center center no-repeat fixed;
  height:100%; 
}


.nav ul li {
  width:20px;
  background-color:white;
  height:20px;
  display:inline-block;
  margin-right:20px; 
}
.nav ul li:last-child {
  margin-right:0px;
}

.nav {
  position: absolute;
  bottom:100px;
  left:50%;
  transform:translate(-50%,-50%);
}

.nav ul .active{
  background-color:black;
}

.two, .three, .four {
  display:none;
}


  </style>

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何使用v-for显示背景图像?

来自分类Dev

如何使用纯JS检查显示哪个背景图像

来自分类Dev

如何始终显示背景图像的中心?

来自分类Dev

背景图像未使用 CSS 显示

来自分类Dev

“隐藏/显示”元素并更改按钮背景图像

来自分类Dev

如何避免Chrome在自动填充输入中隐藏背景图像和颜色

来自分类Dev

在<AbsoluteLayout>中隐藏edittext和背景图像撤回

来自分类Dev

如何使用CSS在前景图像上显示背景图像

来自分类Dev

如何删除画布背景并显示完整背景图像

来自分类Dev

如何使用Tkinter添加背景图像

来自分类Dev

如何使用jquery设置背景图像

来自分类Dev

如何使用JavaScript使背景图像透明

来自分类Dev

仅部分图像显示为我的背景图像。如何使用CSS获取完整图像作为背景?

来自分类Dev

仅部分图像显示为我的背景图像。如何使用CSS获取完整的图像作为背景?

来自分类Dev

如何显示背景图像,直到图像加载

来自分类Dev

如何显示背景图像,直到图像加载

来自分类Dev

如何使用背景位置和百分比值制作可拖动的背景图像?

来自分类Dev

如何在QGraphicsScene或QGraphicsView上显示/隐藏背景图?

来自分类Dev

如何在QGraphicsScene或QGraphicsView上显示/隐藏背景图?

来自分类Dev

透明的JTextField和JLabel显示背景图像

来自分类Dev

显示和更改外部SVG背景图像

来自分类Dev

CSS:悬停问题显示元素和背景图像

来自分类Dev

不显示背景图像

来自分类Dev

背景图像无显示

来自分类Dev

背景图像未显示

来自分类Dev

显示完整的背景图像

来自分类Dev

使用javascript设置图像源和背景图像

来自分类Dev

如何使用光滑的滑块显示全屏背景图像滑块?

来自分类Dev

如何使用jquery和css使用动画更改单击背景图像

Related 相关文章

  1. 1

    如何使用v-for显示背景图像?

  2. 2

    如何使用纯JS检查显示哪个背景图像

  3. 3

    如何始终显示背景图像的中心?

  4. 4

    背景图像未使用 CSS 显示

  5. 5

    “隐藏/显示”元素并更改按钮背景图像

  6. 6

    如何避免Chrome在自动填充输入中隐藏背景图像和颜色

  7. 7

    在<AbsoluteLayout>中隐藏edittext和背景图像撤回

  8. 8

    如何使用CSS在前景图像上显示背景图像

  9. 9

    如何删除画布背景并显示完整背景图像

  10. 10

    如何使用Tkinter添加背景图像

  11. 11

    如何使用jquery设置背景图像

  12. 12

    如何使用JavaScript使背景图像透明

  13. 13

    仅部分图像显示为我的背景图像。如何使用CSS获取完整图像作为背景?

  14. 14

    仅部分图像显示为我的背景图像。如何使用CSS获取完整的图像作为背景?

  15. 15

    如何显示背景图像,直到图像加载

  16. 16

    如何显示背景图像,直到图像加载

  17. 17

    如何使用背景位置和百分比值制作可拖动的背景图像?

  18. 18

    如何在QGraphicsScene或QGraphicsView上显示/隐藏背景图?

  19. 19

    如何在QGraphicsScene或QGraphicsView上显示/隐藏背景图?

  20. 20

    透明的JTextField和JLabel显示背景图像

  21. 21

    显示和更改外部SVG背景图像

  22. 22

    CSS:悬停问题显示元素和背景图像

  23. 23

    不显示背景图像

  24. 24

    背景图像无显示

  25. 25

    背景图像未显示

  26. 26

    显示完整的背景图像

  27. 27

    使用javascript设置图像源和背景图像

  28. 28

    如何使用光滑的滑块显示全屏背景图像滑块?

  29. 29

    如何使用jquery和css使用动画更改单击背景图像

热门标签

归档