123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="utf-8">
- <title>jQuery幻灯片插件Owl Carousel演示-进度条_dowebok</title>
- <style>
- #owl-demo { width: 900px; margin-left: auto; margin-right: auto;}
- #owl-demo .item{ display: block;}
- #owl-demo img { display: block; width: 100%; border: 0 none;}
- #bar{ width: 0%; max-width: 100%; height: 4px; background: #7fc242; overflow: hidden;}
- #progressBar{ width: 100%; background: #ededed;}
- </style>
- <link href="css/owl.carousel.css" rel="stylesheet">
- <link href="css/owl.theme.css" rel="stylesheet">
- <script src="http://cdn.staticfile.org/jquery/1.8.3/jquery.min.js"></script>
- <script src="js/owl.carousel.js"></script>
- <script>
- $(function(){
- var time = 7; //进度条时间,以秒为单位,越小越快
- var $progressBar, $bar, $elem, isPause, tick, percentTime;
- $('#owl-demo').owlCarousel({
- slideSpeed: 500,
- paginationSpeed: 500,
- singleItem: true,
- afterInit: progressBar,
- afterMove: moved,
- startDragging: pauseOnDragging
- });
- function progressBar(elem){
- $elem = elem;
- buildProgressBar();
- start();
- }
- function buildProgressBar(){
- $progressBar = $('<div>',{
- id:'progressBar'
- });
- $bar = $('<div>',{
- id:'bar'
- });
- $progressBar.append($bar).insertAfter($elem.children().eq(0));
- }
- function start(){
- percentTime = 0;
- isPause = false;
- tick = setInterval(interval, 10);
- }
- function interval(){
- if(isPause === false){
- percentTime += 1 / time;
- $bar.css({
- width: percentTime+'%'
- });
- if(percentTime >= 100){
- $elem.trigger('owl.next')
- }
- }
- }
- function pauseOnDragging(){
- isPause = true;
- }
- function moved(){
- clearTimeout(tick);
- start();
- }
- $elem.on('mouseover',function(){
- isPause = true;
- })
- $elem.on('mouseout',function(){
- isPause = false;
- });
- });
- </script>
- </head>
- <body>
- <div class="menu">
- <p class="menuc">
- <span></span>
- <a href="./">1、默认</a>
- <a href="index2.html">2、单个</a>
- <a href="index3.html">3、自动播放</a>
- <a href="index4.html">4、显示上一张/下一张</a>
- <a href="index5.html">5、自适应高度</a>
- <a href="index6.html">6、延迟加载(Lazy Load)</a>
- <a href="index7.html">7、加载JSON</a>
- <a href="index8.html">8、自定义JSON</a>
- <a class="cur" href="index9.html">9、进度条</a>
- <a href="index10.html">10、随机显示</a>
- </p>
- </div>
- <div class="main">
- <div class="mianc">
- <h1>进度条</h1>
- <!-- Demo -->
- <div id="owl-demo" class="owl-carousel">
- <a class="item"><img src="img/fullimage1.jpg" alt=""></a>
- <a class="item"><img src="img/fullimage2.jpg" alt=""></a>
- <a class="item"><img src="img/fullimage3.jpg" alt=""></a>
- <a class="item"><img src="img/fullimage4.jpg" alt=""></a>
- <a class="item"><img src="img/fullimage5.jpg" alt=""></a>
- </div>
- <!-- Demo end -->
- <div class="code">
- <h3 class="h31 cur">JavaScript</h3>
- <div class="pre">
- <pre class="pre-show prettyprint linenums">$(function(){
- var time = 7; //进度条时间,以秒为单位,越小越快
- var $progressBar, $bar, $elem, isPause, tick, percentTime;
- $('#owl-demo').owlCarousel({
- slideSpeed: 500,
- paginationSpeed: 500,
- singleItem: true,
- afterInit: progressBar,
- afterMove: moved,
- startDragging: pauseOnDragging
- });
- function progressBar(elem){
- $elem = elem;
- buildProgressBar();
- start();
- }
- function buildProgressBar(){
- $progressBar = $('<div>',{
- id:'progressBar'
- });
- $bar = $('<div>',{
- id:'bar'
- });
- $progressBar.append($bar).insertAfter($elem.children().eq(0));
- }
- function start(){
- percentTime = 0;
- isPause = false;
- tick = setInterval(interval, 10);
- }
- function interval(){
- if(isPause === false){
- percentTime += 1 / time;
- $bar.css({
- width: percentTime+'%'
- });
- if(percentTime >= 100){
- $elem.trigger('owl.next')
- }
- }
- }
- function pauseOnDragging(){
- isPause = true;
- }
- function moved(){
- clearTimeout(tick);
- start();
- }
- $elem.on('mouseover',function(){
- isPause = true;
- })
- $elem.on('mouseout',function(){
- isPause = false;
- });
- });</pre>
- </div>
- <h3 class="h32">HTML</h3>
- <div class="pre">
- <pre class="pre-show prettyprint linenums"><div id="owl-demo" class="owl-carousel">
- <a class="item"><img src="img/fullimage1.jpg" alt=""></a>
- <a class="item"><img src="img/fullimage2.jpg" alt=""></a>
- <a class="item"><img src="img/fullimage3.jpg" alt=""></a>
- <a class="item"><img src="img/fullimage4.jpg" alt=""></a>
- <a class="item"><img src="img/fullimage5.jpg" alt=""></a>
- </div></pre>
- </div>
- <h3 class="h33">CSS</h3>
- <div class="pre">
- <pre class="pre-show prettyprint linenums">#owl-demo {
- width: 900px;
- margin-left: auto;
- margin-right: auto;
- }
- #owl-demo .item {
- display: block;
- }
- #owl-demo img {
- display: block;
- width: 100%;
- border: 0 none;
- }
- #bar {
- width: 0%;
- max-width: 100%;
- height: 4px;
- background: #7fc242;
- overflow: hidden;
- }
- #progressBar {
- width: 100%;
- background: #ededed;
- }</pre>
- </div>
- </div>
- <p class="vad">
- <a href="http://www.dowebok.com/" target="_blank">dowebok.com</a>
- <a href="http://www.dowebok.com/93.html" target="_blank">说 明</a>
- <a href="http://www.dowebok.com/93.html" target="_blank">下 载</a>
- </p>
- </div>
- </div>
- <!-- 以下是统计及其他信息,与演示无关,不必理会 -->
- <style>
- * { margin: 0; padding: 0;}
- html, body { height: 100%; overflow: hidden;}
- body { font-family: Consolas,arial,"宋体";}
- .menu { position: absolute; left: 0; top: 0; width: 200px; height: 100%; background-color: #ccc; font-family: Consolas,arial,"宋体";}
- .menuc { height: 100%; overflow-x: hidden; overflow-y: auto;}
- .menu span { display: block; height: 100px;}
- .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;}
- .menu a:hover { background-color: #eee;}
- .menu .cur { color: #000; background-color: #fff !important;}
- .main { height: 100%; margin-left: 200px;}
- .mianc { position: relative; height: 100%; overflow-x: hidden; overflow-y: auto;}
- .main h1 { width: 900px; margin: 40px auto; font: 32px "Microsoft Yahei";}
- .explain, .dowebok-explain { margin-top: 20px; font-size: 14px; text-align: center; color: #f50;}
- .vad { margin: 50px 0 10px; font-family: Consolas,arial,宋体,sans-serif; text-align:center;}
- .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;}
- .vad a:hover { color: #fff; background-color: #000;}
- .thead { width: 728px; height: 90px; margin: 0 auto; border-bottom: 40px solid transparent;}
- .code { position: relative; margin-top: 100px; padding-top: 41px;}
- .code h3 { position: absolute; top: 0; z-index: 10; width: 100px; height: 40px; font: 16px/40px "Microsoft Yahei"; text-align: center; cursor: pointer;}
- .code .cur { border: 1px solid #f0f0f0; border-bottom: 1px solid #f8f8f8; background-color: #f8f8f8;}
- .code .h31 { left: 0;}
- .code .h32 { left: 102px;}
- .code .h33 { left: 204px;}
- .code .h34 { left: 306px;}
- .code { width: 900px; margin-left: auto; margin-right: auto;}
- pre { padding: 15px 0; border: 1px solid #f0f0f0; background-color: #f8f8f8;}
- .f-dn { display: none;}
- </style>
- <link href="http://xww-global.u.qiniudn.com/prettify.css" rel="stylesheet">
- <script src="http://xww-global.u.qiniudn.com/prettify.js"></script>
- <script>
- window.prettyPrint && prettyPrint();
- $('.code h3').not(':first').next().addClass('f-dn');
- $('.code h3').click(function(){
- $(this).addClass('cur').siblings('h3').removeClass('cur');
- $(this).next().removeClass('f-dn').siblings('.pre').addClass('f-dn');
- });
- </script>
- </body>
- </html>
|