当前位置:Gxlcms > JavaScript > 基于JQuery实现图片轮播效果(焦点图)_jquery

基于JQuery实现图片轮播效果(焦点图)_jquery

时间:2021-07-01 10:21:17 帮助过:6人阅读

自己写了一个纯jq形式的横向轮播焦点图,可点击小圆点或者左右按钮进行切换,属于定宽类型。改成自适应宽度的也不难,将css里面的bannerCon宽度改为百分比,再在js里面将ul和li的宽度跟随父级容器的宽度变化即可,需要用到$(window).resize。

兼容到IE6+以上浏览器,有轮播速度和切换间隔两个参数可以改。

效果图如下:

Html代码如下:

  1. <meta charset="utf-8">
  2. <title>banner图</title>

Css样式如下:

  1. @charset "utf-8";
  2. /* 简单reset */
  3. body, p, ul, ol, li {
  4. margin: 0;
  5. padding: 0;
  6. }
  7. ul, ol {
  8. list-style: none;
  9. }
  10. img { border:none; }
  11. a,button{ outline: none; }
  12. .clearfix:after {
  13. visibility: hidden;
  14. display: block;
  15. font-size: 0;
  16. content: " ";
  17. clear: both;
  18. height: 0;
  19. }
  20. /* 具体样式 */
  21. .banner {
  22. position: relative;
  23. height: 400px;
  24. overflow: hidden;
  25. }
  26. .banner .bannerCon {
  27. position: absolute;
  28. top: 0;
  29. left: 50%;
  30. width: 800px;
  31. height: 400px;
  32. margin-left: -400px;
  33. overflow: hidden;
  34. }
  35. .bannerCon .imgList {
  36. position: absolute;
  37. top: 0;
  38. left: 0;
  39. width: 99999px;
  40. height: 400px;
  41. }
  42. .bannerCon .imgList li {
  43. float: left;
  44. width: 800px;
  45. height: 400px;
  46. }
  47. .bannerCon .imgList li a {
  48. position: relative;
  49. display: block;
  50. height: 100%;
  51. }
  52. .bannerCon .imgList li img {
  53. width: 800px;
  54. height: 400px;
  55. }
  56. .bannerCon .pre-nex {
  57. display: none;
  58. position: absolute;
  59. top: 50%;
  60. width: 40px;
  61. height: 60px;
  62. margin-top: -40px;
  63. font: bold 40px/60px Simsun;
  64. color: #ccc;
  65. text-align: center;
  66. border:none;
  67. background: rgba(0,0,0,.30);
  68. filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr=#4c000000, endColorStr=#4c000000);
  69. cursor: pointer;
  70. z-index: 3;
  71. }
  72. .bannerCon .pre-nex.show { display: inline-block; }
  73. .bannerCon .prev { left: 13%; }
  74. .bannerCon .next { right: 13%; }
  75. .bannerCon .btnList {
  76. position: absolute;
  77. left: 0;
  78. bottom: 20px;
  79. width: 100%;
  80. height: 12px;
  81. text-align:center;
  82. z-index: 2;
  83. _overflow: hidden;
  84. }
  85. .bannerCon .btnList li { display: inline; }
  86. .bannerCon .btnList li span {
  87. display: inline-block;
  88. width: 12px;
  89. height: 12px;
  90. margin: 0 5px;
  91. border-radius: 6px;
  92. background-color:#14829e;
  93. cursor: pointer;
  94. }
  95. .bannerCon .btnList li.cur span { background-color: #f30; }

Js代码如下:

注意加载一下jq库,我用的是1.9.1的,其实1.7+的都没问题的。

以上就是本文的全部内容,希望能够帮助大家。

人气教程排行