nongfengBooth.js
6.7 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/**
* 广告系统
* zzf
*/
var DILIAD = function(arges){
var config,methods,template,controller,port,animation;
//配置
config = {
httpUrl : "http://apd.nong12.com/apd/getJsonp",//请求地址
httpId : 0,//请求ID
httpDataType : "jsonp",//请求数据类型
httpType : "GET",//请求数据方式
showType : ["roll", "vertical", "ordinary"],//展示数据方式
view : ""//当前显示对象
};
//数据获取
methods = {
getData : function(){//获取数据
var url = config.httpUrl +"?id="+ config.httpId;
$.ajax({
url : url,
type : config.httpType,
dataType : config.httpDataType,
jsonp: 'callback',
error : function(x, t, e){
controller.errorView("服务器code:"+x.status);
},
success : function(response){
if(response.showType){
var page = config.showType[response.showType - 1];
animation[page](response);
}
}
});
}
};
//动画渲染样式
animation = {
arges : {
width : 0,
length : 0,
direction : "left",
dir : true,
time : null,
index : 0
},
roll : function(data){//横滚
var view,length,width;
view = template.lsit(data.data);
this.calculate(view, data);
length = data.data.length;
width = length * data.width;
config.view.find(".ad-cont").width(width);
this.slide(data.width, length, "left");
},
vertical : function(data){//垂直
var view,length,height;
view = template.lsit(data.data);
this.calculate(view, data);
length = data.data.length;
height = length * data.height;
config.view.find(".ad-cont").height(height);
this.slide(data.height, length, "top");
},
upPage : function(index){
var view = config.view.find(".ad-page");
view.find("span").removeClass("on");
view.find("span").eq(index).addClass("on");
},
ordinary : function(data){//图片
var view;
view = template.view(data.img);
this.calculate(view, data);
},
slide : function (width, length, direction) {//滑动
this.arges.index = 0;
this.arges.width = width;
this.arges.length = length;
this.arges.direction = direction;
this.arges.dir = true;
this.setTime();
controller.event();
},
sport : function(istime){
var opt = {};
opt[animation.arges.direction] = -(animation.arges.index * animation.arges.width);
config.view.find(".ad-cont").stop().animate(opt, 800);
animation.upPage(animation.arges.index);
if(istime){this.setTime()};
},
setTime : function(){
animation.arges.time = setInterval(function(){
if((animation.arges.index < (animation.arges.length - 1)) && animation.arges.dir){
animation.arges.index ++ ;
}else{
if(animation.arges.index <= 0){
animation.arges.index ++ ;
animation.arges.dir = true;
}else{
animation.arges.dir=false;
};
animation.arges.index -- ;
}
animation.sport();
}, 3000);
},
calculate : function(view, data){//设置数据
config.view.html($(view));
config.view.width(data.width).height(data.height);
config.view.find("li").width(data.width).height(data.height);
config.view.find(".ad-page").css("margin-left", -config.view.find(".ad-page").width()/2);
try{
$(".ad-roll img").imageLoad(0);
}catch (error){};
}
};
//模板定义
template = {
lsit : function(data){//多图展示类型
var sub = "";
var view = "<div class='ad-cont'><ul>";
for(i in data){
if("0" === i){
sub += "<span class='on'></span>";
}else {
sub += "<span></span>";
}
view += '<li><a href="'+data[i].link+'"><img src="http://static.nong12.com/static/newStatic/pnr/images/blank.gif" data-original="'+data[i].image+'" /></a><p>'+(data[i].text ? data[i].text : "")+'</p></li>';
}
view += '</ul></div><div class="ad-page">'+sub+'</div>';
return view;
},
view : function(data){//单图展示类型
var view = '<div class="ad-cont"><a href="'+data.link+'"><img src="'+data.image+'" /></a></div>';
return view;
}
};
//控制器
controller = {
errorView : function(text){//异常处理
config.view.html(text);
},
init : function(){//初始化
if(arges.id && arges.viewId){
config.httpId = arges.id;
config.view = $("#"+arges.viewId);
config.view.addClass("ad ad-roll");
methods.getData();
}else{
this.errorView("请绑定视图ID 或者 传入广告ID");
};
$("head").append('<link type="text/css" rel="stylesheet" href="http://static.nong12.com/static/newStatic/pnr/nongfengBooth/nongfengBooth.css"/>');
},
event : function(width, direction){
var view = config.view.find(".ad-page");
view.on("click", "span", function(){
animation.arges.index = $(this).index();
clearInterval(animation.arges.time);
animation.sport(true);
});
}
};
//外部接口
port = {};
controller.init();
return port;
};
$(function(){
//首页轮播
var indexBanner = new DILIAD({
id : "33333",
viewId : "banner"
});
//1楼
var index1 = new DILIAD({
id : "90001",
viewId : "species1"
});
//2楼
var index2 = new DILIAD({
id : "90002",
viewId : "species2"
});
//3楼
var index3 = new DILIAD({
id : "90003",
viewId : "species3"
});
//4楼
var index4 = new DILIAD({
id : "90004",
viewId : "species4"
});
//5楼
var index5 = new DILIAD({
id : "90005",
viewId : "species5"
});
});