当前位置:   article > 正文

JS 实现3D立体效果的首页轮播图(瞬间让你的网站高大上,逼格满满)

前端3d轮播切换特效

这里写图片描述

还是那句话,废话少说,直接上源代码:http://download.csdn.net/detail/cometwo/9387901

  1. <html>
  2. <head>
  3. <title>JS 实现3D立体效果的图片幻灯切换</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
  5. <style>
  6. html {background:#000}
  7. body, ul {margin:0;padding:0}
  8. li {list-style:none}
  9. img {border:none;display:block}
  10. .slide-wp {
  11. width: 500px;
  12. height: 300px;
  13. overflow: hidden;
  14. position: absolute;
  15. left: 50%;
  16. top: 50%;
  17. margin-left: -250px;
  18. margin-top: -150px;
  19. }
  20. .nav-wp {
  21. position: absolute;
  22. background: #ccc;
  23. top: 50%;
  24. margin-top: 170px;
  25. left: 50%;
  26. margin-left: -100px;
  27. border-radius: 4px;
  28. -moz-border-radius: 4px;
  29. -webkit-border-radius: 4px;
  30. padding: 0 20px 6px 10px;
  31. _padding: 0 20px 2px 10px;
  32. }
  33. .nav li {
  34. float: left;
  35. margin-left: 10px;
  36. font-size: 20px;
  37. font-weight: bold;
  38. font-family: tahoma;
  39. color: #22739e;
  40. cursor: pointer;
  41. height: 22px;
  42. }
  43. .nav li.cur{color: #ff7a00}
  44. .next {
  45. position:absolute;
  46. top: 0;
  47. left: 160px;
  48. padding: 4px 8px;
  49. color: #ff7a00;
  50. background: #ccc;
  51. height: 20px;
  52. border-radius: 4px;
  53. -moz-border-radius: 4px;
  54. -webkit-border-radius: 4px;
  55. cursor: pointer;
  56. }
  57. </style>
  58. </head>
  59. <body>
  60. <h2 style="color:#fff">对于使用IE6的同学看到的斑点,我只能表示很无奈。。。</h2>
  61. <div id="slider" class="slide-wp">
  62. <ul>
  63. <li><a href="http://www.newxing.com/" target="_blank"><img src="http://www.newxing.com/img/450/1.jpg" alt="" /></a></li>
  64. <li><a href="http://www.newxing.com/" target="_blank"><img src="http://www.newxing.com/img/450/2.jpg" alt="" /></a></li>
  65. <li><a href="http://www.newxing.com/" target="_blank"><img src="http://www.newxing.com/img/450/3.jpg" alt="" /></a></li>
  66. <li><a href="http://www.newxing.com/" target="_blank"><img src="http://www.newxing.com/img/450/4.jpg" alt="" /></a></li>
  67. <li><a href="http://www.newxing.com/" target="_blank"><img src="http://www.newxing.com/img/450/5.jpg" alt="" /></a></li>
  68. </ul>
  69. </div>
  70. <div class="nav-wp">
  71. <ul id="nav" class="nav">
  72. <li onclick="mySlider.pos(0)"></li>
  73. <li onclick="mySlider.pos(1)"></li>
  74. <li onclick="mySlider.pos(2)"></li>
  75. <li onclick="mySlider.pos(3)"></li>
  76. <li onclick="mySlider.pos(4)"></li>
  77. </ul>
  78. <a class="next" onclick="mySlider.move()">next</a>
  79. </div>
  80. <script type="text/javascript">
  81. var HR = {
  82. $ : function(i) {return document.getElementById(i)},
  83. $$ : function(c, p) {return p.getElementsByTagName(c)},
  84. ce : function(i, t) {
  85. var o = document.createElement(i);
  86. t.appendChild(o);
  87. return o;
  88. }
  89. };
  90. HR.slider3D = function () {
  91. var init = function (o) {
  92. this.o = o;
  93. var wp = HR.$(o.id), ul = HR.$$('ul', wp)[0], li = this.li = HR.$$('li', ul);
  94. this.l = li.length;
  95. this.w = wp.offsetWidth;
  96. this.h = wp.offsetHeight;
  97. this.at = o.auto? o.auto : 4;
  98. var con = this.con = HR.ce('div', wp);
  99. con.style.cssText = 'position:absolute;left:0;top:0;width:'+this.w+'px;height:'+this.h+'px';
  100. ul.style['display'] = 'none';
  101. this.a1 = HR.ce('a', con);
  102. this.a1.style.cssText = 'position:absolute;left:0;top:0;overflow:hidden';
  103. this.a2 = HR.ce('a', con);
  104. this.a2.style.cssText = 'position:absolute;top:0;right:0;overflow:hidden';
  105. this.a1.innerHTML = this.a2.innerHTML = '<img alt="" />';
  106. this.img = HR.$$('img', ul);
  107. this.s = o.maskSize ? o.maskSize : 5;
  108. this.mask11 = HR.ce('span', this.a1);
  109. this.mask12 = HR.ce('span', this.a1);
  110. this.mask21 = HR.ce('span', this.a2);
  111. this.mask22 = HR.ce('span', this.a2);
  112. this.pos(0);
  113. }
  114. init.prototype = {
  115. pos : function (i) {
  116. clearInterval(this.li[i].a); clearInterval(this.au); this.au = 0; this.cur = i;
  117. var navli = HR.$$('li', HR.$(this.o.navId));
  118. for (var j=0; j<navli.length; j++) {
  119. navli[j].className = i == j ? 'cur' : '';
  120. }
  121. var img1 = HR.$$('img', this.a1)[0], img2 = HR.$$('img', this.a2)[0], _this = this;
  122. img1.src = i==0 ? this.img[this.l-1].src : this.img[i-1].src;
  123. img1.width = this.w;
  124. img2.src = this.img[i].src;
  125. img2.width = 0;
  126. img1.height = img2.height = this.h;
  127. this.mask11.style.cssText = 'position:absolute;left:0;top:0;font-size:0;overflow:hidden;width:0;height:0;border-color:black transparent transparent black;border-style:solid dashed dashed solid;border-width:0 '+this.w/2+'px';
  128. this.mask12.style.cssText = 'position:absolute;left:0;bottom:0;font-size:0;overflow:hidden;width:0;height:0;border-color:transparent transparent black black;border-style:dashed dashed solid solid;border-width:0 '+this.w/2+'px';
  129. this.mask21.style.cssText = 'position:absolute;right:0;top:0;font-size:0;overflow:hidden;width:0;height:0;border-color:black black transparent transparent;border-style:solid solid dashed dashed;border-width:0px';
  130. this.mask22.style.cssText = 'position:absolute;right:0;bottom:0;font-size:0;overflow:hidden;width:0;height:0;border-color:transparent black black transparent;border-style:dashed solid solid dashed;border-width:0px';
  131. this.li[i].a = setInterval(function(){_this.anim(i)}, 20);
  132. },
  133. anim : function (i) {
  134. var w1 = HR.$$('img', this.a1)[0].width, w2 = HR.$$('img', this.a2)[0].width;
  135. if (w2 == this.w) {
  136. clearInterval(this.li[i].a);
  137. HR.$$('img', this.a1)[0].width = 0;
  138. HR.$$('img', this.a2)[0].width = this.w;
  139. this.mask11.style.borderLeftWidth = this.mask11.style.borderRightWidth = this.mask12.style.borderLeftWidth = this.mask12.style.borderRightWidth = '0px';
  140. this.mask11.style.borderTopWidth = this.mask11.style.borderBottomWidth = this.mask12.style.borderTopWidth = this.mask12.style.borderBottomWidth = this.h/this.s + 'px';
  141. this.mask21.style.borderLeftWidth = this.mask21.style.borderRightWidth = this.mask22.style.borderLeftWidth = this.mask22.style.borderRightWidth = this.w/2 + 'px';
  142. this.mask21.style.borderTopWidth = this.mask21.style.borderBottomWidth = this.mask22.style.borderTopWidth = this.mask22.style.borderBottomWidth = '0px';
  143. }else {
  144. HR.$$('img', this.a1)[0].width -= Math.ceil((this.w-w2)*.13);
  145. HR.$$('img', this.a2)[0].width += Math.ceil((this.w-w2)*.13);
  146. this.mask11.style.borderLeftWidth = this.mask11.style.borderRightWidth = this.mask12.style.borderLeftWidth = this.mask12.style.borderRightWidth = HR.$$('img', this.a1)[0].width/2 + 'px';
  147. this.mask11.style.borderTopWidth = this.mask11.style.borderBottomWidth = this.mask12.style.borderTopWidth = this.mask12.style.borderBottomWidth = HR.$$('img', this.a2)[0].width*this.h/(this.s*this.w) + 'px';
  148. this.mask21.style.borderLeftWidth = this.mask21.style.borderRightWidth = this.mask22.style.borderLeftWidth = this.mask22.style.borderRightWidth = HR.$$('img', this.a2)[0].width/2 + 'px';
  149. this.mask21.style.borderTopWidth = this.mask21.style.borderBottomWidth = this.mask22.style.borderTopWidth = this.mask22.style.borderBottomWidth = this.h/this.s - HR.$$('img', this.a2)[0].width*this.h/(this.s*this.w) + 'px';
  150. if (!this.au) this.auto();
  151. }
  152. },
  153. auto : function () {
  154. var _this = this;
  155. this.au = setInterval(function(){_this.move()}, this.at*1000);
  156. },
  157. move : function () {
  158. var n = this.cur==this.l-1 ? 0 : this.cur+1;
  159. this.pos(n);
  160. }
  161. }
  162. return init;
  163. }();
  164. var mySlider = new HR.slider3D({
  165. id: 'slider',
  166. maskSize: 6,
  167. navId: 'nav',
  168. auto: 4
  169. })</SCRIPT></body>
  170. </html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172

高级扩展

这里写图片描述

  1. <html>
  2. <head>
  3. <title>JS 实现3D立体效果的图片幻灯切换</title>
  4. <meta charset="utf-8" />
  5. <style>
  6. html {
  7. background: #000
  8. }
  9. body,
  10. ul {
  11. left: 0px;
  12. top: 0px;
  13. margin: 0;
  14. padding: 0
  15. }
  16. h1{
  17. border: 1px solid blue;
  18. text-align: center;
  19. color:red;
  20. padding: 10px;
  21. font-size: 25px;
  22. }
  23. li,a,img {
  24. display: block;
  25. list-style: none;
  26. border: none;
  27. }
  28. .slide-wp {
  29. height: 400px;
  30. width:100%;
  31. overflow: hidden;
  32. position: relative;
  33. margin: 0 auto;
  34. border: 1px solid red;
  35. }
  36. .slide-wp ul {
  37. position: relative;
  38. }
  39. .nav-wp {
  40. position: absolute;
  41. background: #ccc;
  42. top: 50%;
  43. margin-top: 170px;
  44. left: 50%;
  45. margin-left: -100px;
  46. border-radius: 4px;
  47. -moz-border-radius: 4px;
  48. -webkit-border-radius: 4px;
  49. padding: 0 20px 6px 10px;
  50. _padding: 0 20px 2px 10px;
  51. }
  52. .nav li {
  53. float: left;
  54. margin-left: 10px;
  55. font-size: 20px;
  56. font-weight: bold;
  57. font-family: tahoma;
  58. color: blue; /*默认颜色*/
  59. cursor: pointer;
  60. height:20px;
  61. }
  62. .nav li.cur {
  63. color: red;
  64. }
  65. .next {
  66. position: absolute;
  67. top: 0;
  68. left: 160px;
  69. padding: 4px 8px;
  70. color: #ff7a00;
  71. background: #ccc;
  72. height: 20px;
  73. border-radius: 4px;
  74. -moz-border-radius: 4px;
  75. -webkit-border-radius: 4px;
  76. cursor: pointer;
  77. }
  78. </style>
  79. </head>
  80. <body>
  81. <h1>IE6可能不支持</h1>
  82. <div id="slider" class="slide-wp">
  83. <ul>
  84. <li>
  85. <a href="http://www.newxing.com/" target="_blank"><img src="img/img1.jpg" alt="" /></a>
  86. </li>
  87. <li>
  88. <a href="http://www.newxing.com/" target="_blank"><img src="img/img2.jpg" alt="" /></a>
  89. </li>
  90. <li>
  91. <a href="http://www.newxing.com/" target="_blank"><img src="img/img3.jpg" alt="" /></a>
  92. </li>
  93. <li>
  94. <a href="http://www.newxing.com/" target="_blank"><img src="img/img4.jpg" alt="" /></a>
  95. </li>
  96. <li>
  97. <a href="http://www.newxing.com/" target="_blank"><img src="img/img5.jpg" alt="" /></a>
  98. </li>
  99. </ul>
  100. </div>
  101. <div class="nav-wp">
  102. <ul id="nav" class="nav">
  103. <li onclick="mySlider.pos(0)"></li>
  104. <li onclick="mySlider.pos(1)"></li>
  105. <li onclick="mySlider.pos(2)"></li>
  106. <li onclick="mySlider.pos(3)"></li>
  107. <li onclick="mySlider.pos(4)"></li>
  108. </ul>
  109. <a class="next" onclick="mySlider.move()">next</a>
  110. </div>
  111. <script type="text/javascript">
  112. var HR = {
  113. $: function(i) {
  114. return document.getElementById(i)
  115. },
  116. $$: function(c, p) {
  117. return p.getElementsByTagName(c)
  118. },
  119. ce: function(i, t) {
  120. var o = document.createElement(i);
  121. t.appendChild(o);
  122. return o;
  123. }
  124. };
  125. HR.slider3D = function() {
  126. var init = function(o) {
  127. this.o = o;
  128. var wp = HR.$(o.id),
  129. ul = HR.$$('ul', wp)[0],
  130. li = this.li = HR.$$('li', ul);
  131. this.l = li.length;
  132. this.w = wp.offsetWidth;
  133. this.h = wp.offsetHeight;
  134. this.at = o.auto ? o.auto : 4;
  135. var con = this.con = HR.ce('div', wp);
  136. con.style.cssText = 'position:absolute;left:0;top:0;width:' + this.w + 'px;height:' + this.h + 'px';
  137. ul.style['display'] = 'none';
  138. this.a1 = HR.ce('a', con);
  139. this.a1.style.cssText = 'position:absolute;left:0;top:0;overflow:hidden';
  140. this.a2 = HR.ce('a', con);
  141. this.a2.style.cssText = 'position:absolute;top:0;right:0;overflow:hidden';
  142. this.a1.innerHTML = this.a2.innerHTML = '<img alt="" />';
  143. this.img = HR.$$('img', ul);
  144. this.s = o.maskSize ? o.maskSize : 5;
  145. this.mask11 = HR.ce('span', this.a1);
  146. this.mask12 = HR.ce('span', this.a1);
  147. this.mask21 = HR.ce('span', this.a2);
  148. this.mask22 = HR.ce('span', this.a2);
  149. this.pos(0);
  150. }
  151. init.prototype = {
  152. pos: function(i) {
  153. clearInterval(this.li[i].a);
  154. clearInterval(this.au);
  155. this.au = 0;
  156. this.cur = i;
  157. var navli = HR.$$('li', HR.$(this.o.navId));
  158. for (var j = 0; j < navli.length; j++) {
  159. navli[j].className = i == j ? 'cur' : '';
  160. }
  161. var img1 = HR.$$('img', this.a1)[0],
  162. img2 = HR.$$('img', this.a2)[0],
  163. _this = this;
  164. img1.src = i == 0 ? this.img[this.l - 1].src : this.img[i - 1].src;
  165. img1.width = this.w;
  166. img2.src = this.img[i].src;
  167. img2.width = 0;
  168. img1.height = img2.height = this.h;
  169. this.mask11.style.cssText = 'position:absolute;left:0;top:0;font-size:0;overflow:hidden;width:0;height:0;border-color:black transparent transparent black;border-style:solid dashed dashed solid;border-width:0 ' + this.w / 2 + 'px';
  170. this.mask12.style.cssText = 'position:absolute;left:0;bottom:0;font-size:0;overflow:hidden;width:0;height:0;border-color:transparent transparent black black;border-style:dashed dashed solid solid;border-width:0 ' + this.w / 2 + 'px';
  171. this.mask21.style.cssText = 'position:absolute;right:0;top:0;font-size:0;overflow:hidden;width:0;height:0;border-color:black black transparent transparent;border-style:solid solid dashed dashed;border-width:0px';
  172. this.mask22.style.cssText = 'position:absolute;right:0;bottom:0;font-size:0;overflow:hidden;width:0;height:0;border-color:transparent black black transparent;border-style:dashed solid solid dashed;border-width:0px';
  173. this.li[i].a = setInterval(function() {
  174. _this.anim(i)
  175. }, 20); //规定多长时间完成翻转
  176. },
  177. anim: function(i) {
  178. var w1 = HR.$$('img', this.a1)[0].width,
  179. w2 = HR.$$('img', this.a2)[0].width;
  180. if (w2 == this.w) {
  181. clearInterval(this.li[i].a);
  182. HR.$$('img', this.a1)[0].width = 0;
  183. HR.$$('img', this.a2)[0].width = this.w;
  184. this.mask11.style.borderLeftWidth = this.mask11.style.borderRightWidth = this.mask12.style.borderLeftWidth = this.mask12.style.borderRightWidth = '0px';
  185. this.mask11.style.borderTopWidth = this.mask11.style.borderBottomWidth = this.mask12.style.borderTopWidth = this.mask12.style.borderBottomWidth = this.h / this.s + 'px';
  186. this.mask21.style.borderLeftWidth = this.mask21.style.borderRightWidth = this.mask22.style.borderLeftWidth = this.mask22.style.borderRightWidth = this.w / 2 + 'px';
  187. this.mask21.style.borderTopWidth = this.mask21.style.borderBottomWidth = this.mask22.style.borderTopWidth = this.mask22.style.borderBottomWidth = '0px';
  188. } else {
  189. HR.$$('img', this.a1)[0].width -= Math.ceil((this.w - w2) * .13);
  190. HR.$$('img', this.a2)[0].width += Math.ceil((this.w - w2) * .13);
  191. this.mask11.style.borderLeftWidth = this.mask11.style.borderRightWidth = this.mask12.style.borderLeftWidth = this.mask12.style.borderRightWidth = HR.$$('img', this.a1)[0].width / 2 + 'px';
  192. this.mask11.style.borderTopWidth = this.mask11.style.borderBottomWidth = this.mask12.style.borderTopWidth = this.mask12.style.borderBottomWidth = HR.$$('img', this.a2)[0].width * this.h / (this.s * this.w) + 'px';
  193. this.mask21.style.borderLeftWidth = this.mask21.style.borderRightWidth = this.mask22.style.borderLeftWidth = this.mask22.style.borderRightWidth = HR.$$('img', this.a2)[0].width / 2 + 'px';
  194. this.mask21.style.borderTopWidth = this.mask21.style.borderBottomWidth = this.mask22.style.borderTopWidth = this.mask22.style.borderBottomWidth = this.h / this.s - HR.$$('img', this.a2)[0].width * this.h / (this.s * this.w) + 'px';
  195. if (!this.au) this.auto();
  196. }
  197. },
  198. auto: function() {
  199. var _this = this;
  200. this.au = setInterval(function() {
  201. _this.move()
  202. }, this.at * 1000); //翻转频率,看150行
  203. },
  204. move: function() {
  205. var n = this.cur == this.l - 1 ? 0 : this.cur + 1;
  206. this.pos(n);
  207. }
  208. }
  209. return init;
  210. }();
  211. var mySlider = new HR.slider3D({
  212. id: 'slider',
  213. maskSize: 6, //banner图张数
  214. navId: 'nav',
  215. auto: 1 //设置翻转频率,看150行
  216. })
  217. </SCRIPT>
  218. </body>
  219. </html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224
  • 225
  • 226
  • 227
  • 228
  • 229
  • 230
  • 231
  • 232
  • 233
  • 234
  • 235

这里写图片描述

  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>全屏图片切换</title>
  6. <script type="text/javascript" src="js/jquery-2.1.4.min.js"></script>
  7. <script type="text/javascript" src="js/jquery.flexslider-min.js"></script>
  8. <script type="text/javascript">
  9. $(document).ready(function() {
  10. $('.flexslider').flexslider({
  11. directionNav: true,
  12. pauseOnAction: false,
  13. animation: "slide",
  14. slideshowSpeed: 700
  15. });
  16. });
  17. </script>
  18. <style type="text/css">
  19. * {
  20. margin: 0;
  21. padding: 0;
  22. list-style-type: none;
  23. }
  24. a,
  25. img {
  26. border: 0;
  27. }
  28. body {
  29. font: 12px/180% Arial, Helvetica, sans-serif, "新宋体";
  30. }
  31. /* flexslider */
  32. .flexslider {
  33. position: relative;
  34. height: 400px;
  35. width: 100%;
  36. overflow: hidden;
  37. background: url(img/loading.gif) 50% no-repeat;
  38. margin: 0 auto;
  39. }
  40. .slides {
  41. position: relative;
  42. z-index: 1;
  43. }
  44. .slides li {
  45. height: 600px;
  46. }
  47. .flex-control-nav {
  48. position: absolute;
  49. bottom: 10px;
  50. z-index: 2;
  51. width: 100%;
  52. text-align: center;
  53. }
  54. .flex-control-nav li {
  55. display: inline-block;
  56. width: 14px;
  57. height: 14px;
  58. margin: 0 5px;
  59. *display: inline;
  60. zoom: 1;
  61. }
  62. .flex-control-nav a {
  63. display: inline-block;
  64. width: 14px;
  65. height: 14px;
  66. line-height: 40px;
  67. overflow: hidden;
  68. background: url(img/dot.png) right 0 no-repeat;
  69. cursor: pointer;
  70. }
  71. .flex-control-nav .flex-active {
  72. background-position: 0 0;
  73. }
  74. .flex-direction-nav {
  75. position: absolute;
  76. z-index: 3;
  77. width: 100%;
  78. top: 45%;
  79. }
  80. .flex-direction-nav li a {
  81. display: block;
  82. width: 50px;
  83. height: 50px;
  84. overflow: hidden;
  85. cursor: pointer;
  86. position: absolute;
  87. }
  88. .flex-direction-nav li a.flex-prev {
  89. left: 40px;
  90. background: url(img/prev.png) center center no-repeat;
  91. }
  92. .flex-direction-nav li a.flex-next {
  93. right: 40px;
  94. background: url(img/next.png) center center no-repeat;
  95. }
  96. </style>
  97. </head>
  98. <body>
  99. <div style="height:20px;overflow:hidden;">banner图</div>
  100. <div class="flexslider">
  101. <ul class="slides">
  102. <li style="background:url(img/img1.jpg) 50% 0 no-repeat;"></li>
  103. <li style="background:url(img/img2.jpg) 50% 0 no-repeat;"></li>
  104. <li style="background:url(img/img3.jpg) 50% 0 no-repeat;"></li>
  105. <li style="background:url(img/img4.jpg) 50% 0 no-repeat;"></li>
  106. <li style="background:url(img/img5.jpg) 50% 0 no-repeat;"></li>
  107. </ul>
  108. </div>
  109. <pre>
  110. $(window).load(function() {
  111. $('.flexslider').flexslider({
  112. animation: "fade", //String: Select your animation type, "fade" or "slide" 图片变换方式:淡入淡出或者滑动
  113. slideDirection: "horizontal", //String: Select the sliding direction, "horizontal" or "vertical" 图片设置为滑动式时的滑动方向:左右或者上下
  114. slideshow: true, //Boolean: Animate slider automatically 载入页面时,是否自动播放
  115. slideshowSpeed: 7000, //Integer: Set the speed of the slideshow cycling, in milliseconds 自动播放速度毫秒
  116. animationDuration: 600, //Integer: Set the speed of animations, in milliseconds 动画淡入淡出效果延时
  117. directionNav: true, //Boolean: Create navigation for previous/next navigation? (true/false) 是否显示左右控制按钮
  118. controlNav: true, //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage 是否显示控制菜单
  119. keyboardNav: true, //Boolean: Allow slider navigating via keyboard left/right keys 键盘左右方向键控制图片滑动
  120. mousewheel: false, //Boolean: Allow slider navigating via mousewheel 鼠标滚轮控制制图片滑动
  121. prevText: "Previous", //String: Set the text for the "previous" directionNav item 设置文本的字符串:“以前的”directionnav项目
  122. nextText: "Next", //String: Set the text for the "next" directionNav item 看过《文本字符串:“下”的directionnav item
  123. pausePlay: false, //Boolean: Create pause/play dynamic element 布尔:create暂停/播放动态元素
  124. pauseText: 'Pause', //String: Set the text for the "pause" pausePlay item 字符串:设置文字为“暂停”pauseplay项目
  125. playText: 'Play', //String: Set the text for the "play" pausePlay item 字符串:在“玩”pauseplay项设置文本
  126. randomize: false, //Boolean: Randomize slide order 是否随即幻灯片
  127. slideToStart: 0, //Integer: The slide that the slider should start on. Array notation (0 = first slide)初始化第一次显示图片位置
  128. animationLoop: true, //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end 是否循环滚动
  129. pauseOnAction: true, //Boolean: Pause the slideshow when interacting with control elements, highly recommended. 布尔:暂停幻灯片的控制要素互动的时候,强烈推荐。
  130. pauseOnHover: false, //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering 布尔:暂停幻灯片演示当鼠标悬停的滑块,然后恢复时不再徘徊
  131. controlsContainer: "", //Selector: Declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be ".flexslider-container", "#container", etc. If the given element is not found, the default action will be taken. 该导航元素的容器说,这应该是appended太。默认的容器是flexslider元。实例的使用将是“容器”,# .flexslider“容器”,等等。如果没有发现了元素的默认行为,将被考虑。
  132. manualControls: "", //Selector: Declare custom control navigation. Example would be ".flex-control-nav li" or "#tabs-nav li img", etc. The number of elements in your controlNav should match the number of slides/tabs.自定义控制导航
  133. manualControlEvent:"", //String:自定义导航控制触发事件:默认是click,可以设定hover
  134. start: function(){}, //Callback: function(slider) - Fires when the slider loads the first slide 回调:功能(滑块)-当滑块加载第一个幻灯片时触发
  135. before: function(){}, //Callback: function(slider) - Fires asynchronously with each slider animation 回调:功能(滑块)-与每个滑块动画异步触发
  136. after: function(){}, //Callback: function(slider) - Fires after each slider animation completes 回调:功能(滑块)-每个滑块动画完成后触发
  137. end: function(){} //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous) 当滑块到达上一个幻灯片(异步)时发生火灾
  138. });
  139. });
  140. </pre>
  141. </body>
  142. </html>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160

配置参数

  1. <pre>
  2. $(window).load(function() {
  3. $('.flexslider').flexslider({
  4. animation: "fade", //String: Select your animation type, "fade" or "slide" 图片变换方式:淡入淡出或者滑动
  5. slideDirection: "horizontal", //String: Select the sliding direction, "horizontal" or "vertical" 图片设置为滑动式时的滑动方向:左右或者上下
  6. slideshow: true, //Boolean: Animate slider automatically 载入页面时,是否自动播放
  7. slideshowSpeed: 7000, //Integer: Set the speed of the slideshow cycling, in milliseconds 自动播放速度毫秒
  8. animationDuration: 600, //Integer: Set the speed of animations, in milliseconds 动画淡入淡出效果延时
  9. directionNav: true, //Boolean: Create navigation for previous/next navigation? (true/false) 是否显示左右控制按钮
  10. controlNav: true, //Boolean: Create navigation for paging control of each clide? Note: Leave true for manualControls usage 是否显示控制菜单
  11. keyboardNav: true, //Boolean: Allow slider navigating via keyboard left/right keys 键盘左右方向键控制图片滑动
  12. mousewheel: false, //Boolean: Allow slider navigating via mousewheel 鼠标滚轮控制制图片滑动
  13. prevText: "Previous", //String: Set the text for the "previous" directionNav item 设置文本的字符串:“以前的”directionnav项目
  14. nextText: "Next", //String: Set the text for the "next" directionNav item 看过《文本字符串:“下”的directionnav item
  15. pausePlay: false, //Boolean: Create pause/play dynamic element 布尔:create暂停/播放动态元素
  16. pauseText: 'Pause', //String: Set the text for the "pause" pausePlay item 字符串:设置文字为“暂停”pauseplay项目
  17. playText: 'Play', //String: Set the text for the "play" pausePlay item 字符串:在“玩”pauseplay项设置文本
  18. randomize: false, //Boolean: Randomize slide order 是否随即幻灯片
  19. slideToStart: 0, //Integer: The slide that the slider should start on. Array notation (0 = first slide)初始化第一次显示图片位置
  20. animationLoop: true, //Boolean: Should the animation loop? If false, directionNav will received "disable" classes at either end 是否循环滚动
  21. pauseOnAction: true, //Boolean: Pause the slideshow when interacting with control elements, highly recommended. 布尔:暂停幻灯片的控制要素互动的时候,强烈推荐。
  22. pauseOnHover: false, //Boolean: Pause the slideshow when hovering over slider, then resume when no longer hovering 布尔:暂停幻灯片演示当鼠标悬停的滑块,然后恢复时不再徘徊
  23. controlsContainer: "", //Selector: Declare which container the navigation elements should be appended too. Default container is the flexSlider element. Example use would be ".flexslider-container", "#container", etc. If the given element is not found, the default action will be taken. 该导航元素的容器说,这应该是appended太。默认的容器是flexslider元。实例的使用将是“容器”,# .flexslider“容器”,等等。如果没有发现了元素的默认行为,将被考虑。
  24. manualControls: "", //Selector: Declare custom control navigation. Example would be ".flex-control-nav li" or "#tabs-nav li img", etc. The number of elements in your controlNav should match the number of slides/tabs.自定义控制导航
  25. manualControlEvent:"", //String:自定义导航控制触发事件:默认是click,可以设定hover
  26. start: function(){}, //Callback: function(slider) - Fires when the slider loads the first slide 回调:功能(滑块)-当滑块加载第一个幻灯片时触发
  27. before: function(){}, //Callback: function(slider) - Fires asynchronously with each slider animation 回调:功能(滑块)-与每个滑块动画异步触发
  28. after: function(){}, //Callback: function(slider) - Fires after each slider animation completes 回调:功能(滑块)-每个滑块动画完成后触发
  29. end: function(){} //Callback: function(slider) - Fires when the slider reaches the last slide (asynchronous) 当滑块到达上一个幻灯片(异步)时发生火灾
  30. });
  31. });
  32. </pre>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/834602
推荐阅读
相关标签
  

闽ICP备14008679号