index9.html 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery幻灯片插件Owl Carousel演示-进度条_dowebok</title>
  6. <style>
  7. #owl-demo { width: 900px; margin-left: auto; margin-right: auto;}
  8. #owl-demo .item{ display: block;}
  9. #owl-demo img { display: block; width: 100%; border: 0 none;}
  10. #bar{ width: 0%; max-width: 100%; height: 4px; background: #7fc242; overflow: hidden;}
  11. #progressBar{ width: 100%; background: #ededed;}
  12. </style>
  13. <link href="css/owl.carousel.css" rel="stylesheet">
  14. <link href="css/owl.theme.css" rel="stylesheet">
  15. <script src="http://cdn.staticfile.org/jquery/1.8.3/jquery.min.js"></script>
  16. <script src="js/owl.carousel.js"></script>
  17. <script>
  18. $(function(){
  19. var time = 7; //进度条时间,以秒为单位,越小越快
  20. var $progressBar, $bar, $elem, isPause, tick, percentTime;
  21. $('#owl-demo').owlCarousel({
  22. slideSpeed: 500,
  23. paginationSpeed: 500,
  24. singleItem: true,
  25. afterInit: progressBar,
  26. afterMove: moved,
  27. startDragging: pauseOnDragging
  28. });
  29. function progressBar(elem){
  30. $elem = elem;
  31. buildProgressBar();
  32. start();
  33. }
  34. function buildProgressBar(){
  35. $progressBar = $('<div>',{
  36. id:'progressBar'
  37. });
  38. $bar = $('<div>',{
  39. id:'bar'
  40. });
  41. $progressBar.append($bar).insertAfter($elem.children().eq(0));
  42. }
  43. function start(){
  44. percentTime = 0;
  45. isPause = false;
  46. tick = setInterval(interval, 10);
  47. }
  48. function interval(){
  49. if(isPause === false){
  50. percentTime += 1 / time;
  51. $bar.css({
  52. width: percentTime+'%'
  53. });
  54. if(percentTime >= 100){
  55. $elem.trigger('owl.next')
  56. }
  57. }
  58. }
  59. function pauseOnDragging(){
  60. isPause = true;
  61. }
  62. function moved(){
  63. clearTimeout(tick);
  64. start();
  65. }
  66. $elem.on('mouseover',function(){
  67. isPause = true;
  68. })
  69. $elem.on('mouseout',function(){
  70. isPause = false;
  71. });
  72. });
  73. </script>
  74. </head>
  75. <body>
  76. <div class="menu">
  77. <p class="menuc">
  78. <span></span>
  79. <a href="./">1、默认</a>
  80. <a href="index2.html">2、单个</a>
  81. <a href="index3.html">3、自动播放</a>
  82. <a href="index4.html">4、显示上一张/下一张</a>
  83. <a href="index5.html">5、自适应高度</a>
  84. <a href="index6.html">6、延迟加载(Lazy Load)</a>
  85. <a href="index7.html">7、加载JSON</a>
  86. <a href="index8.html">8、自定义JSON</a>
  87. <a class="cur" href="index9.html">9、进度条</a>
  88. <a href="index10.html">10、随机显示</a>
  89. </p>
  90. </div>
  91. <div class="main">
  92. <div class="mianc">
  93. <h1>进度条</h1>
  94. <!-- Demo -->
  95. <div id="owl-demo" class="owl-carousel">
  96. <a class="item"><img src="img/fullimage1.jpg" alt=""></a>
  97. <a class="item"><img src="img/fullimage2.jpg" alt=""></a>
  98. <a class="item"><img src="img/fullimage3.jpg" alt=""></a>
  99. <a class="item"><img src="img/fullimage4.jpg" alt=""></a>
  100. <a class="item"><img src="img/fullimage5.jpg" alt=""></a>
  101. </div>
  102. <!-- Demo end -->
  103. <div class="code">
  104. <h3 class="h31 cur">JavaScript</h3>
  105. <div class="pre">
  106. <pre class="pre-show prettyprint linenums">$(function(){
  107. var time = 7; //进度条时间,以秒为单位,越小越快
  108. var $progressBar, $bar, $elem, isPause, tick, percentTime;
  109. $('#owl-demo').owlCarousel({
  110. slideSpeed: 500,
  111. paginationSpeed: 500,
  112. singleItem: true,
  113. afterInit: progressBar,
  114. afterMove: moved,
  115. startDragging: pauseOnDragging
  116. });
  117. function progressBar(elem){
  118. $elem = elem;
  119. buildProgressBar();
  120. start();
  121. }
  122. function buildProgressBar(){
  123. $progressBar = $('&lt;div&gt;',{
  124. id:'progressBar'
  125. });
  126. $bar = $('&lt;div&gt;',{
  127. id:'bar'
  128. });
  129. $progressBar.append($bar).insertAfter($elem.children().eq(0));
  130. }
  131. function start(){
  132. percentTime = 0;
  133. isPause = false;
  134. tick = setInterval(interval, 10);
  135. }
  136. function interval(){
  137. if(isPause === false){
  138. percentTime += 1 / time;
  139. $bar.css({
  140. width: percentTime+'%'
  141. });
  142. if(percentTime &gt;= 100){
  143. $elem.trigger('owl.next')
  144. }
  145. }
  146. }
  147. function pauseOnDragging(){
  148. isPause = true;
  149. }
  150. function moved(){
  151. clearTimeout(tick);
  152. start();
  153. }
  154. $elem.on('mouseover',function(){
  155. isPause = true;
  156. })
  157. $elem.on('mouseout',function(){
  158. isPause = false;
  159. });
  160. });</pre>
  161. </div>
  162. <h3 class="h32">HTML</h3>
  163. <div class="pre">
  164. <pre class="pre-show prettyprint linenums">&lt;div id="owl-demo" class="owl-carousel"&gt;
  165. &lt;a class="item"&gt;&lt;img src="img/fullimage1.jpg" alt=""&gt;&lt;/a&gt;
  166. &lt;a class="item"&gt;&lt;img src="img/fullimage2.jpg" alt=""&gt;&lt;/a&gt;
  167. &lt;a class="item"&gt;&lt;img src="img/fullimage3.jpg" alt=""&gt;&lt;/a&gt;
  168. &lt;a class="item"&gt;&lt;img src="img/fullimage4.jpg" alt=""&gt;&lt;/a&gt;
  169. &lt;a class="item"&gt;&lt;img src="img/fullimage5.jpg" alt=""&gt;&lt;/a&gt;
  170. &lt;/div&gt;</pre>
  171. </div>
  172. <h3 class="h33">CSS</h3>
  173. <div class="pre">
  174. <pre class="pre-show prettyprint linenums">#owl-demo {
  175. width: 900px;
  176. margin-left: auto;
  177. margin-right: auto;
  178. }
  179. #owl-demo .item {
  180. display: block;
  181. }
  182. #owl-demo img {
  183. display: block;
  184. width: 100%;
  185. border: 0 none;
  186. }
  187. #bar {
  188. width: 0%;
  189. max-width: 100%;
  190. height: 4px;
  191. background: #7fc242;
  192. overflow: hidden;
  193. }
  194. #progressBar {
  195. width: 100%;
  196. background: #ededed;
  197. }</pre>
  198. </div>
  199. </div>
  200. <p class="vad">
  201. <a href="http://www.dowebok.com/" target="_blank">dowebok.com</a>
  202. <a href="http://www.dowebok.com/93.html" target="_blank">说 明</a>
  203. <a href="http://www.dowebok.com/93.html" target="_blank">下 载</a>
  204. </p>
  205. </div>
  206. </div>
  207. <!-- 以下是统计及其他信息,与演示无关,不必理会 -->
  208. <style>
  209. * { margin: 0; padding: 0;}
  210. html, body { height: 100%; overflow: hidden;}
  211. body { font-family: Consolas,arial,"宋体";}
  212. .menu { position: absolute; left: 0; top: 0; width: 200px; height: 100%; background-color: #ccc; font-family: Consolas,arial,"宋体";}
  213. .menuc { height: 100%; overflow-x: hidden; overflow-y: auto;}
  214. .menu span { display: block; height: 100px;}
  215. .menu a { display: block; height: 40px; margin: 0 0 1px 2px; padding-left: 10px; line-height: 40px; font-size: 14px; color: #333; text-decoration: none;}
  216. .menu a:hover { background-color: #eee;}
  217. .menu .cur { color: #000; background-color: #fff !important;}
  218. .main { height: 100%; margin-left: 200px;}
  219. .mianc { position: relative; height: 100%; overflow-x: hidden; overflow-y: auto;}
  220. .main h1 { width: 900px; margin: 40px auto; font: 32px "Microsoft Yahei";}
  221. .explain, .dowebok-explain { margin-top: 20px; font-size: 14px; text-align: center; color: #f50;}
  222. .vad { margin: 50px 0 10px; font-family: Consolas,arial,宋体,sans-serif; text-align:center;}
  223. .vad a { display: inline-block; height: 36px; line-height: 36px; margin: 0 5px; padding: 0 50px; font-size: 14px; text-align:center; color:#eee; text-decoration: none; background-color: #222;}
  224. .vad a:hover { color: #fff; background-color: #000;}
  225. .thead { width: 728px; height: 90px; margin: 0 auto; border-bottom: 40px solid transparent;}
  226. .code { position: relative; margin-top: 100px; padding-top: 41px;}
  227. .code h3 { position: absolute; top: 0; z-index: 10; width: 100px; height: 40px; font: 16px/40px "Microsoft Yahei"; text-align: center; cursor: pointer;}
  228. .code .cur { border: 1px solid #f0f0f0; border-bottom: 1px solid #f8f8f8; background-color: #f8f8f8;}
  229. .code .h31 { left: 0;}
  230. .code .h32 { left: 102px;}
  231. .code .h33 { left: 204px;}
  232. .code .h34 { left: 306px;}
  233. .code { width: 900px; margin-left: auto; margin-right: auto;}
  234. pre { padding: 15px 0; border: 1px solid #f0f0f0; background-color: #f8f8f8;}
  235. .f-dn { display: none;}
  236. </style>
  237. <link href="http://xww-global.u.qiniudn.com/prettify.css" rel="stylesheet">
  238. <script src="http://xww-global.u.qiniudn.com/prettify.js"></script>
  239. <script>
  240. window.prettyPrint && prettyPrint();
  241. $('.code h3').not(':first').next().addClass('f-dn');
  242. $('.code h3').click(function(){
  243. $(this).addClass('cur').siblings('h3').removeClass('cur');
  244. $(this).next().removeClass('f-dn').siblings('.pre').addClass('f-dn');
  245. });
  246. </script>
  247. </body>
  248. </html>