photoslide.js
4.83 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
/**
* @package plugin/photoslide.js
* @author:ww(wei.wang@yoho.cn)
* @date:2014-08-19
*/
var $=require("jquery");
require("jquery.imagesloaded");
var tmpInfo=null;
window.onresize=function(){
exports.initSlide(tmpInfo);
};
exports.initSlide=function(info){
tmpInfo=info;
var defaults={
isMobile:false,
mobileStartDrage:window.photoSlide_StartDrage||function(){},
mobileEndDrage:function(){},
isAndroid:false //是否为安卓客户端程序
};
var opts=$.extend(defaults,info);
var isMobile=opts.isMobile;
var photos=$(".photoslider_moused_over");
if(photos.length>0)
{
var maxWidth={},maxHeight={};
var brow=getBrowType();
photos.each(function(index,obj){
//alert(index);
var tmpId="photoslider_moused_over_"+index;
$(obj).attr("id",tmpId);
var imgs={};
$(obj).find(".photoslider_right_image").find("img:first").css({"max-width":"100%"}).imagesLoaded(function(){
imgs[tmpId]=$(this).attr("src");
maxWidth[tmpId]=$(this).width();
maxHeight[tmpId]=$(this).height();
$(obj).find(".photoslider_left_image img").css({
"max-width":maxWidth[tmpId],
"max-height":maxHeight[tmpId],
"min-width":maxWidth[tmpId],
"min-height":maxHeight[tmpId],
"width":maxWidth[tmpId],
"height":maxHeight[tmpId]
}).show();
$(".photoslider_drag_message")
.html("← SLIDE →")
.show();
//var u = navigator.userAgent;
if(isMobile&&$(obj).find(".drageObject")[0]===null||brow.bIsIpad||brow.bIsAndroid)
{
$("<div/>").css({
position:"absolute",
height:maxHeight[tmpId]*0.2,
width:maxWidth[tmpId],
top:0,
left:0,
"z-index":100
}).attr("noslider","yes").appendTo(obj);
$("<div/>").css({
position:"absolute",
height:maxHeight[tmpId]*0.3,
width:maxWidth[tmpId],
bottom:0,
left:0,
"z-index":100
//background:"#f00"
}).attr("noslider","yes").appendTo(obj);
var drageObject=$("<div/>").attr("class","drageObject").css({
width:20,
height:"100%",
margin:"0 0 0 -10px",
top:0,
left:"50%",
//background:"#f00",
position:"absolute",
"z-index":9999
}).appendTo(obj);
drageObject.bind({
"touchstart":function(){
$(this).parent().find(".photoslider_drag_message").fadeOut();
//opts.mobileStartDrage();
if(opts.isAndroid===true)
{
try{
window.yohoboy.clickOnAndroid(true);
}catch(e){}
}
},
"touchmove":function(event){
var pointX = event.originalEvent.changedTouches[0].pageX;
var left=$(this).parent().offset().left;
var mouseX=pointX-left;
if(mouseX<$(this).parent().parent().width()&&mouseX>0)
{
$(this).parent().find(".photoslider_left_image").width(mouseX);
$(this).css({left:mouseX});
//return false;
}
return false;
},
"touchend":function(){
if(opts.isAndroid===true)
{
try{
window.yohoboy.clickOnAndroid(false);
}catch(e){}
}
}
});
//var self=this;
}
});
});
if(isMobile||brow.bIsIpad||brow.bIsAndroid)
{
window.onresize=function(){
exports.initSlide(info);
//var tmpHtml=$(this).parent().parent().parent().html();
};
}
if(isMobile===false)
photos.bind({
"mousemove":function(event){
var pointX = event.pageX;
var left=$(this).offset().left;
var mouseX=pointX-left;
if(mouseX<maxWidth[this.id]&&(!isMobile))
{
$(this).find(".photoslider_left_image").width(mouseX);
//$(this).find(".photoslider_drag_message").css({left:mouseX});
}
},
"mouseover":function(){
var drag_handler=$(this).find(".photoslider_drag_message");
drag_handler.fadeOut();
},
mouseout:function(event){
var x=event.pageX;
if(x-$(this).offset().left>maxWidth[this.id])
{
$(this).find(".photoslider_left_image").width(maxWidth[this.id]);
}
else if(x-$(this).offset().left<0){
$(this).find(".photoslider_left_image").width(0);
}
}
});
}
};
function getBrowType(){
var info={};
var sUserAgent = navigator.userAgent.toLowerCase();
info.bIsIpad = sUserAgent.match(/ipad/i) == "ipad";
info.bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";
info.bIsMidp = sUserAgent.match(/midp/i) == "midp";
info.bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";
info.bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";
info.bIsAndroid = sUserAgent.match(/android/i) == "android";
info.bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";
info.bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";
return info;
}