jquery.eeyellow.Timeline.js
5.4 KB
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
; (function ($, window, document, undefined) {
//'use strict';
var pluginName = 'vivaTimeline';//Plugin名稱
//Timeline建構式
var Timeline = function (element, opt) {
//私有變數
this.target = element;
this.carouselInterval;
this.checkImgLoad;
this.imgLoad = false;
//初始化
this._init(opt);
this._event();
}
//ImportKML2D預設參數
Timeline.options = {
carousel: true,
carouselTime: 10000
}
//Timeline私有方法
Timeline.prototype = {
//初始化
_init: function (_opt) {
//合併自訂參數與預設參數
var self = this;
self.options = $.extend(true, {}, Timeline.options, _opt);
self.target
.find('.events-body')
.each(function(){
var rowcount = $(this).find('.row').length;
if(rowcount > 1) {
var html = "<ol>";
for(var i = 0; i < rowcount; i++){
html += "<li data-target='" + i + "'></li>";
}
html += "</ol>";
$(this)
.siblings('.events-footer')
.html(html)
.find('li')
.first()
.addClass('active');
}
});
self.target
.find('.events-body')
.each(function(){
$(this)
.find('.row')
.first()
.show()
.siblings()
.hide();
});
self.target
.find('img').on('load', function(){
self.target
.find('.events-body')
.each(function(){
var maxHeight = 0;
$(this)
.find('.row')
.each(function(){
if($(this).height() > maxHeight){
maxHeight = $(this).height();
}
});
$(this).find('.row').height(maxHeight);
});
});
},
//綁定事件
_event: function () {
var self = this;
self.target
.find('.events-header')
.click(function(){
$(this)
.siblings('.events-body').slideToggle()
.end()
.siblings('.events-footer').toggle();
});
self.target
.find('.events-footer li')
.click(function(){
self._carousel($(this));
});
if(self.options.carousel){
self.carouselInterval = setInterval(function(){
self._carousel();
}, self.options.carouselTime);
self.target
.find('.events')
.hover(function(){
clearInterval(self.carouselInterval);
self.carouselInterval = null;
}, function(){
if(self.carouselInterval == undefined){
self.carouselInterval = setInterval(function(){
self._carousel();
}, self.options.carouselTime);
}
});
}
},
//自動輪播
_carousel: function(_container) {
var self = this;
if(_container == undefined){
self.target
.find('.events-footer .active')
.each(function(){
var nextTarget;
if($(this).is(':last-child')){
nextTarget = $(this).siblings().first();
}
else{
nextTarget = $(this).next();
}
self._carousel(nextTarget);
});
}
else{
var target = _container.data().target;
_container
.addClass('active')
.siblings()
.removeClass('active');
_container
.closest('.events-footer')
.siblings('.events-body')
.find('.row')
.eq(target).show()
.siblings().hide();
}
}
}
//公開方法
$.fn[pluginName] = function (options, args) {
var timeline;
this.each(function () {
timeline = new Timeline($(this), options);
});
return this;
}
})(jQuery, window, document);