经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » HTML/CSS » CSS » 查看文章
html5+css如何实现中间大两头小的轮播效果
来源:jb51  时间:2018/12/10 9:21:37  对本文有异议

国际惯例,先上效果

好了,话不多说,上去就是一顿撸。

css:

  1. <style>
  2.  
  3. *{margin: 0;padding: 0}
  4. .wrap{
  5. }
  6. .container{
  7. width: 100%;
  8. overflow: hidden;
  9. /* height: 400px; */
  10. background: red;
  11. position: relative;
  12. }
  13. .box{width: 125%;
  14. height: auto;
  15. display: flex;
  16. align-items: center;
  17. position: relative;
  18. left: 0;
  19. }
  20. .box li{
  21. width: 20%;
  22. float: left;
  23. list-style: none;
  24. -webkit-transition: width 0.5s, height 0.5s, margin 0.5s;
  25. position: relative;
  26. }
  27. .box video {
  28. width: 100%;
  29. height: 100%;
  30. }
  31. .box li div {
  32. position: absolute;
  33. top: 0;
  34. bottom: 0;
  35. left: 0;
  36. right: 0;
  37. }
  38. .box li div img {
  39. width: 100%;
  40. height: 100%;
  41. }
  42. /* .box li:nth-child(2){
  43. height: 360px;
  44. margin: 0 1%;
  45. } */
  46. .goLeft, .goRight {
  47. position: absolute;
  48. width: 28px;
  49. height: 52px;
  50. top: 50%;
  51. transform: translate(0,-50%);
  52. cursor: pointer;
  53. border: none;
  54. outline: none;
  55. line-height: 52px;
  56. }
  57. .goLeft {
  58. left: 20%;
  59. }
  60. .goRight {
  61. right: 20%;
  62. }
  63. .box li>p {
  64. margin: 0;
  65. color: #fff;
  66. position: absolute;
  67. top: 50%;
  68. left: 50%;
  69. transform: translate(-50%,-50%);
  70. text-align: center;
  71. }
  72. .box li>p>span {
  73. display: inline-block;
  74. width: 100px;
  75. height: 100px;
  76. background: url(play.png);
  77. }
  78. .ddd{
  79. width: 100%;
  80. height: 360px;
  81. display: flex;
  82. align-items: center;
  83. position: relative;
  84. }
  85. .dd-2{
  86. width: 20%;
  87. background: yellow;
  88. }
  89. .aa{
  90. width: 100%;
  91. }
  92. </style>
  93.  

html:

  1. <div class="wrap">
  2.  
  3. <div class="container">
  4. <ul class="box">
  5. <li class="video1">
  6. <video></video>
  7. <div><img src="3.jpg" alt="">1</div>
  8. </li>
  9. <li class="video2">
  10. <video></video>
  11. <div><img src="3.jpg" alt="">2</div>
  12. </li>
  13. <li class="video3">
  14. <video></video>
  15. <div><img src="3.jpg" alt="">3</div>
  16. </li>
  17. <li class="video4">
  18. <video></video>
  19. <div><img src="3.jpg" alt="">4</div>
  20. </li>
  21. </ul>
  22. <button onclick="moveRight()" class="goLeft btn"></button>
  23. <button onclick="moveLeft()" class="goRight btn"></button>
  24. </div>
  25. <div class="ddd">
  26. <div class="dd-2"><div class="aa">aaa</div><div class="bb">vvvv</div></div>
  27. </div>
  28. </div>

js:

  1. $(function(){
  2. $('.box>li:nth(1)').css({ width: '36%', margin: '0 2%' })
  3. $('.box>li:nth(1)').append('视频主题')
  4. })
  5. $(window).resize(function () { //当浏览器大小变化时
  6. $('.box').css('height', 'auto')
  7. })
  8. function moveLeft(){
  9. var height = $('.box>li:nth(1)').height()
  10. $('.box').css('height', height)
  11. $('.box>li').css({ width: '20%', margin: '0 0%' })
  12. $('.box>li:nth(2)').css({ width: '36%', margin: '0 2%' })
  13. $('.box').animate({
  14. left: '-25%'
  15. }, 400, function () {
  16. // 把第一个子元素移到最后,并且设置left=0
  17. $(".box").append($('.box>li:nth(0)')[0]);
  18. $(".dd-2").append($('.aa')[0]);
  19. $(".aa").append('ccc');
  20. $('.box').css('left', 0);
  21. $(".btn").attr("disabled", false);
  22. $('.box>li:nth(1)').append('视频主题')
  23.  
  24. });
  25. }
  26. function moveRight(){
  27. $('.box>li').css({ width: '20%', margin: '0 0%' })
  28. $('.box>li:nth(0)').css({ width: '36%', margin: '0 2%' })
  29. var height = $('.box>li:nth(1)').height()
  30. $('.box').css('height', height)
  31. $(".box").prepend($('.box>li:nth(3)')[0]);
  32. $('.box').css('left', '-20%');
  33. $('.box').animate({
  34. left: 0
  35. }, 400, function () {
  36. $(".btn").attr("disabled", false);
  37. $('.box>li:nth(1)').append('视频主题')
  38. });
  39. }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号