Slideshow.js
4.5 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
//*
// 图片轮播
// */
import Loger from "../Loger";
import Ape from "./Ape";
import $ from "jquery";
import ClassDataProxy from "proxy/ClassDataProxy";
import MessageTypes from "../MessageTypes";
const SlideList = `
<li class="slidesMap"><img class="slidesImg" src="{_imgList}" data="{_id}" alt=""></li>
`;
let loger = Loger.getLoger('PC-Slideshow');
class Slideshow extends Ape {
constructor() {
super();
this._timer = null;
this.defaultList = ['images/xdybg.png',
'images/bg.jpg',
'images/xdybg.png',
'images/bg.jpg',
'images/xdybg.png'
];
this.dataList = [];
this.dataLength = 0;
this.isLocalStorage();
this.addEvent();
this.init();
}
init() {
$(window).on('resize',this._imgReload.bind(this));
$(".slidesImg").on('load', this._onLoadImage.bind(this));
$('#dots').on('mouseenter',this._mouseenterHandler.bind(this));
$('#dots').on('mouseleave',this._mouseleaveHandler.bind(this));
$('#motionMapBox').on('click','.slidesMap',this._slidesMapHandler.bind(this));
}
addEvent() {
}
isLocalStorage(){
let that = this;
this.detailPage(function (_data) {
if(_data){
let _dataList = _data.returnData.data;
let motionMapBox = $('#motionMapBox');
if(_dataList){
motionMapBox.empty();
for(let i in _dataList){
let _adminList = that._format(SlideList,{
_imgList:_dataList[i].path,
_id:_dataList[i].businessId
})
motionMapBox.append(_adminList)
}
that.dataLength = _dataList.length;
}else{
motionMapBox.empty();
for(let i = 0;i< that.defaultList.length;i++){
let _adminList = that._format(SlideList,{
_imgList:_dataList[i]
})
motionMapBox.append(_adminList)
}
that.dataLength = that.defaultList.length;
}
that.slideImg();
that._imgReload();
}
});
}
detailPage(callback){
let _url = ClassDataProxy.locationProtocol + ClassDataProxy.locationProt + '/upload/getImgBySiteId';
let that = this;
$.ajax({
type: "POST",
url: _url,
data:{siteId:ClassDataProxy.siteId},
headers: {
siteId:ClassDataProxy.siteId,
'token':ClassDataProxy.token
},
success:function(_data){
/* if(_data && _data.code == 200){
loger.log('获取首页图片信息',_data)
}*/
if(_data && _data.code == 200){
if(callback){
callback(_data);
}
}else{
if(callback){
callback(null);
}
}
},
error:function(error){
// console.log(error,'获取首页图片信息失败')
if(callback){
callback(null);
}
}
})
}
_onLoadImage(){
// this._imgReload();
}
slideImg(){
let _num = 0;
let that = this;
clearInterval(this._timer);
this._timer = setInterval(function(){
$('.slidesMap').eq(_num).show().siblings().hide();
_num++;
if(_num > that.dataLength - 1){
_num = 0;
}
},3000);//切换时间
}
_mouseenterHandler(){
clearInterval(this._timer);
}
_mouseleaveHandler(){
// this.slideImg();
}
_slidesMapHandler(evt){
let _id = $(evt.currentTarget).find('.slidesImg').attr('data');
this._emit(MessageTypes.CLICK_IMGINFO,{id:_id});
}
_imgReload(){
let _windowWidth = $("body").width();
$('.slidesMap').css({width:_windowWidth + "px"});
$('.slidesImg').css({"background-size":'auto 100%'});
$('#motionMapBox').width($(".slidesMap").length * _windowWidth)
}
//工具类
_format(str, obj) {
return str.replace(/\{(\w+)\}/g, function (match, group, index) {
return obj[group];
});
};
}
export default Slideshow;