-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
88 lines (75 loc) · 1.92 KB
/
test.js
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
/**
* Created by baiyang on 2016/2/26.
*/
//$(document).ready(function(){
// $("#timings-demo-btn").toggle(
// function(){
// $(this).next("div#timings-demo").addClass("timings-demo-hover");
// },function(){
// $(this).next("div#timings-demo").removeClass("timings-demo-hover");
// });
//});
$(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;
});
$("header").headroom({
"tolerance": 5,
"offset": 205,
"classes": {
"initial": "animated",
"pinned": "swingInX",
"unpinned": "swingOutX"
}
});
});