Skip to content

Commit 8ab1976

Browse files
committed
add slider.js
maybe i will do a slider lib..... simple lib....
1 parent 5cec222 commit 8ab1976

File tree

1 file changed

+127
-115
lines changed

1 file changed

+127
-115
lines changed

轮播图/slider.js

Lines changed: 127 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,128 +1,140 @@
1-
(function(_doc,_win,undefined){
2-
var SliderFactory = (function(){
3-
var id=0;
4-
return function(option){
5-
this.id = id++;
6-
var option = option||{}
7-
var index = 0;
8-
this.ContainerClassSelector = {} //
9-
this.autoPlay = false //是否自动滚动
10-
this.autoinit = false //是否自动初始化
11-
this.clickdelay = false //点击是否开启延迟
12-
this.animate_duration = '1s' //动画变换时间
13-
this.auto_width = true //是手动输入每个元素块的大小(这种情况下通常可以用作按需加载)还是自动获取
14-
this.slider_like = "CSS" //动画函数的效果 是css control or javascript control
15-
this.MODE_SELECT = 1 //三种模式 简单滑动 透明度 无缝滑动
16-
this.hooks = {}
1+
// 实现轮播图的方法。
2+
// 需要div
173

18-
this.init=function(){
19-
20-
}
21-
this.hook = function(name,fn){
22-
var arr = tihs.hook[name]||tihs.hook = [] &&tihs.hook[name]
23-
arr.push(fn)
24-
}
25-
this.firehook = function(name){
26-
var fn = null
27-
while(this.firehook[name]!==void 0&&this.firehook[name].length !== 0){
28-
fn = this.firehook[name].shift()
29-
fn&&fn();
30-
}
4+
5+
(function (_doc, _win, undefined) {
6+
var SliderFactory = (function () {
7+
var id = 0;
8+
return function (option) {
9+
this.id = id++;
10+
var option = option || {}
11+
var index = 0;
12+
this.ContainerClassSelector = {} //
13+
this.autoPlay = false //是否自动滚动
14+
this.autoinit = false //是否自动初始化
15+
this.clickdelay = false //点击是否开启延迟
16+
this.animate_duration = '1s' //动画变换时间
17+
this.auto_width = true //是手动输入每个元素块的大小(这种情况下通常可以用作按需加载)还是自动获取
18+
this.slider_like = "CSS" //动画函数的效果 是css control or javascript control
19+
this.MODE_SELECT = 1 //三种模式 简单滑动 透明度 无缝滑动
20+
this.hooks = {
21+
start: [],
22+
sectionStart: [],
23+
sectionChanging: [],
24+
sectionEnd: [],
25+
end: []
26+
} // 挂载的生命周期
27+
28+
29+
this.mainWorkFlow = function () {
30+
31+
}
32+
this.hook = function (name, fn) {
33+
var arr = tihs.hook[name] || tihs.hook =[] && tihs.hook[name]
34+
arr.push(fn)
35+
}
36+
this.firehook = function (name) {
37+
var fn = null
38+
while (this.firehook[name] !== void 0 && this.firehook[name].length !== 0) {
39+
fn = this.firehook[name].shift()
40+
fn && fn();
3141
}
32-
this.removehook = function(name,fn){
33-
if(!name)return
34-
var index
35-
if(fn){
36-
index = this.firehook[name].indexOf(fn)
37-
delete this.firehook[name][index]
38-
}else{
39-
delete this.firehook[name]
40-
}
42+
return this;
43+
}
44+
this.removehook = function (name, fn) {
45+
if (!name) return
46+
var index
47+
if (fn) {
48+
index = this.firehook[name].indexOf(fn)
49+
delete this.firehook[name][index]
50+
} else {
51+
delete this.firehook[name]
4152
}
42-
function initContainer(obj){
43-
var i
44-
for(i in arr){
45-
if(obj.hasOwnProperty(i)){
46-
this.ContainerClass[i] = this.getOne(pics_pre)
47-
}
53+
}
54+
function initContainer(obj) {
55+
var i
56+
for (i in arr) {
57+
if (obj.hasOwnProperty(i)) {
58+
this.ContainerClass[i] = this.getOne(pics_pre)
4859
}
49-
i = null
5060
}
51-
function initIconList(){
61+
i = null
62+
}
63+
function initIconList() {
5264

65+
}
66+
function initPreBtn(pics_pre) {
67+
this.ContainerClass['pre_btn'] = this.getOne(pics_pre)
68+
return true
69+
}
70+
function initNextBtn(pics_next) {
71+
this.ContainerClass['next_btn'] = this.getOne(pics_next)
72+
return true
73+
}
74+
function initImageList(img_class) {
75+
this.ContainerClass['imgs_container'] = this.getOne(img_class)
76+
return true
77+
}
78+
function wrap(fn) {
79+
if (!(this instanceof SliderFactory)) return new SliderFactory()
80+
return function (args) {
81+
fn.apply(this, args)
5382
}
54-
function initPreBtn(pics_pre){
55-
this.ContainerClass['pre_btn'] = this.getOne(pics_pre)
56-
return true
57-
}
58-
function initNextBtn(pics_next){
59-
this.ContainerClass['next_btn'] = this.getOne(pics_next)
60-
return true
61-
}
62-
function initImageList(img_class){
63-
this.ContainerClass['imgs_container'] = this.getOne(img_class)
64-
return true
65-
}
66-
function wrap(fn){
67-
if(!(this instanceof SliderFactory))return new SliderFactory()
68-
return function(args){
69-
fn.apply(this,args)
70-
}
71-
}
72-
this.mode = function(modes){
73-
switch(modes){
74-
case 'opacity':
83+
}
84+
this.mode = function (modes) {
85+
switch (modes) {
86+
case 'opacity':
7587

76-
}
7788
}
89+
}
7890

91+
}
92+
})()
93+
SliderFactory.prototype = {
94+
constructor: SliderFactory,
95+
isObject: function (obj) {
96+
return Object.prototype.toString.call(null, obj)
97+
},
98+
addEvent: function (ele, eventType, callback, bool) {
99+
if (ele.addEventListener) {
100+
return ele.addEventListener(eventType, callback, !!bool)
101+
} else if (ele.attachEvent) {
102+
return ele.attachEvent(eventType, callback)
103+
} else {
104+
return ele["on" + eventType] = callback
79105
}
80-
})()
81-
SliderFactory.prototype={
82-
constructor:SliderFactory,
83-
isObject:function(obj){
84-
return Object.prototype.toString.call(null,obj)
85-
},
86-
addEvent:function(ele, eventType, callback, bool){
87-
if(ele.addEventListener){
88-
return ele.addEventListener(eventType,callback,!!bool)
89-
}else if(ele.attachEvent){
90-
return ele.attachEvent(eventType,callback)
91-
}else{
92-
return ele["on"+eventType] = callback
93-
}
94-
},
95-
removeEvent:function(ele,eventType,callback,bool){
96-
if(ele.addEventListener){
97-
return ele.removeEventListener(eventType,callback,!!bool)
98-
}else if(ele.attachEvent){
99-
return ele.detachEvent(eventType,callback)
100-
}else{
101-
return ele["on"+eventType] = null
102-
}
103-
},
104-
cancelEvent:function(event){
105-
if(event.preventDefault){
106-
e.preventDefault();
107-
}else{
108-
event.returnValue = false;
109-
}
110-
},
111-
eventstopPropagation:function(event) {
112-
if(event.stopPropagation){
113-
event.stopPropagation()
114-
}else{
115-
event.cancelBubble = true
116-
}
117-
},
118-
eventGet:function(e){
119-
return e||_win.event
120-
},
121-
getAll:function(selector){
122-
return _doc.getSelectorAll(selector)
123-
},
124-
getOne:function(selector){
125-
return _doc.getSelector(selector)
106+
},
107+
removeEvent: function (ele, eventType, callback, bool) {
108+
if (ele.addEventListener) {
109+
return ele.removeEventListener(eventType, callback, !!bool)
110+
} else if (ele.attachEvent) {
111+
return ele.detachEvent(eventType, callback)
112+
} else {
113+
return ele["on" + eventType] = null
114+
}
115+
},
116+
cancelEvent: function (event) {
117+
if (event.preventDefault) {
118+
e.preventDefault();
119+
} else {
120+
event.returnValue = false;
121+
}
122+
},
123+
eventstopPropagation: function (event) {
124+
if (event.stopPropagation) {
125+
event.stopPropagation()
126+
} else {
127+
event.cancelBubble = true
126128
}
129+
},
130+
eventGet: function (e) {
131+
return e || _win.event
132+
},
133+
getAll: function (selector) {
134+
return _doc.getSelectorAll(selector)
135+
},
136+
getOne: function (selector) {
137+
return _doc.getSelector(selector)
127138
}
128-
})(document||{},window||{},void 0)
139+
}
140+
})(document || {}, window || {}, void 0)

0 commit comments

Comments
 (0)