|
@@ -1,22 +1,3 @@
|
1
|
|
-// 请求接口前缀
|
2
|
|
-var Baseurl = "https://xhwebapitest.xhkjedu.com/dh/list";
|
3
|
|
-// $.ajax({
|
4
|
|
-// type: "POST",
|
5
|
|
-// url: Baseurl,
|
6
|
|
-// data: JSON.stringify({
|
7
|
|
-// examid: 434,
|
8
|
|
-// classid: 9666
|
9
|
|
-// }),
|
10
|
|
-// dataType: "json",
|
11
|
|
-// contentType: "application/json; charset=utf-8",
|
12
|
|
-// success: function (data) {
|
13
|
|
-// if (data.code === 0) {
|
14
|
|
-// loadSectionHtml(data.obj);
|
15
|
|
-// } else {
|
16
|
|
-// alert(data.msg);
|
17
|
|
-// }
|
18
|
|
-// }
|
19
|
|
-// });
|
20
|
1
|
var datalist = [
|
21
|
2
|
{ time: 2023 },
|
22
|
3
|
{ time: 2022 },
|
|
@@ -27,20 +8,57 @@ var datalist = [
|
27
|
8
|
{ time: 2017 }
|
28
|
9
|
];
|
29
|
10
|
|
|
11
|
+// 请求接口前缀 3.6.1 中文列表
|
|
12
|
+var Baseurl = "https://xhwebapitest.xhkjedu.com/dh/listc";
|
|
13
|
+$.ajax({
|
|
14
|
+ type: "POST",
|
|
15
|
+ url: Baseurl,
|
|
16
|
+ dataType: "json",
|
|
17
|
+ async: false,
|
|
18
|
+ contentType: "application/json; charset=utf-8",
|
|
19
|
+ success: function (data) {
|
|
20
|
+ if (data.code === 0) {
|
|
21
|
+ datalist = data.obj;
|
|
22
|
+ } else {
|
|
23
|
+ alert(data.msg);
|
|
24
|
+ }
|
|
25
|
+ }
|
|
26
|
+});
|
30
|
27
|
var html = "";
|
31
|
28
|
$.each(datalist, (idx, item) => {
|
32
|
29
|
html += `<div class="round_q" index = "${idx + 1}">
|
33
|
30
|
<div class="round_item">
|
34
|
31
|
<div class="round_i"></div>
|
35
|
|
- <div class="round_d">${item.time}</div>
|
|
32
|
+ <div class="round_d">${item.dhyear}</div>
|
36
|
33
|
</div></div>`;
|
37
|
34
|
});
|
38
|
35
|
$(".rounds").width(datalist.length * 2.34 + "rem");
|
39
|
36
|
$(".rounds").html(html);
|
40
|
37
|
$(".round_q:first").addClass("active"); //默认第一个添加背景色
|
|
38
|
+function showdata(index) {
|
|
39
|
+ var list = datalist[index].details,
|
|
40
|
+ html = '<div class="dev_list">';
|
|
41
|
+ if (!list || list.length == 0) {
|
|
42
|
+ return;
|
|
43
|
+ }
|
|
44
|
+ $.each(list, (idx, item) => {
|
|
45
|
+ if (idx % 4 == 0 && idx) {
|
|
46
|
+ html += '</div><div class="dev_list">';
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ html += `<div class="dev_item" title="${item.content}">
|
|
50
|
+ <span>${item.dhmonth}</span> - ${item.content}
|
|
51
|
+ </div>`;
|
|
52
|
+ });
|
|
53
|
+ if (list.length < 9) {
|
|
54
|
+ html += '</div><div class="dev_list">';
|
|
55
|
+ } else if (list.length < 5) {
|
|
56
|
+ html += '</div><div class="dev_list"></div><div class="dev_list"></div>';
|
|
57
|
+ }
|
|
58
|
+ $(".develop_data").html(html);
|
|
59
|
+}
|
41
|
60
|
//获取元素
|
42
|
61
|
var divwidth = $(".round_q:first").width() - 54;
|
43
|
|
-console.log(divwidth);
|
44
|
62
|
var container = $(".showdata");
|
45
|
63
|
var list = $(".rounds");
|
46
|
64
|
var buts = $(".round_q");
|
|
@@ -53,11 +71,11 @@ var interval = 5000; //位移时间间隔
|
53
|
71
|
var timer;
|
54
|
72
|
var offsetpx = (datalist.length - len) * divwidth; //可偏移度
|
55
|
73
|
var offleft = 0; //当前偏移量
|
56
|
|
-console.log(offsetpx);
|
57
|
74
|
function animate(offset) {
|
58
|
|
- console.log(index);
|
|
75
|
+ if (datalist.length <= 5) {
|
|
76
|
+ return;
|
|
77
|
+ }
|
59
|
78
|
var left = parseInt(list.css("left")) + offset;
|
60
|
|
- console.log(left, offset);
|
61
|
79
|
var absnum = Math.abs(offset);
|
62
|
80
|
if (left < 0 - offsetpx) {
|
63
|
81
|
//右侧没有数据时不偏移
|
|
@@ -67,40 +85,56 @@ function animate(offset) {
|
67
|
85
|
if (offset > 0) {
|
68
|
86
|
offset = "+=" + offset;
|
69
|
87
|
offleft = offleft + absnum;
|
70
|
|
- console.log(offset);
|
71
|
88
|
} else {
|
72
|
89
|
offset = "-=" + Math.abs(offset);
|
73
|
90
|
offleft = offleft - absnum;
|
74
|
|
- console.log(0 - absnum, absnum);
|
75
|
|
- }
|
76
|
|
- // if (index == datalist.length) {
|
77
|
|
- // offset = 0 - (datalist.length - 5) * absnum;
|
78
|
|
- // offleft = offset;
|
79
|
|
- // console.log(offset);
|
80
|
|
- // }
|
81
|
|
- console.log(offset, offleft, "当前偏移量");
|
82
|
|
- if (offset >= 0) {
|
83
|
|
- console.log(44444);
|
|
91
|
+ }
|
|
92
|
+ if (index < 5 && offleft >= 0) {
|
84
|
93
|
return;
|
85
|
94
|
}
|
86
|
95
|
list.animate({ left: offset }, 300, function () {
|
87
|
96
|
if (left > -200) {
|
88
|
|
- console.log(22, (0 - offset) * len);
|
89
|
|
- list.css("left", (0 - offset) * len);
|
|
97
|
+ // list.css("left", (0 - offset) * len);
|
90
|
98
|
}
|
91
|
99
|
if (index == datalist.length) {
|
|
100
|
+ //轮播最后一条
|
92
|
101
|
offset = 0 - (datalist.length - 5) * absnum;
|
93
|
102
|
offleft = offset;
|
94
|
103
|
list.css("left", offset);
|
95
|
|
- console.log(offset, 1231312);
|
96
|
104
|
}
|
97
|
105
|
});
|
98
|
106
|
}
|
|
107
|
+//点击高亮滚动
|
|
108
|
+function animates(offset) {
|
|
109
|
+ if (datalist.length <= 5) {
|
|
110
|
+ return;
|
|
111
|
+ }
|
|
112
|
+ var left = parseInt(list.css("left")) + offset; //获取元素属性
|
|
113
|
+ if (index <= 5 && left >= 0) {
|
|
114
|
+ return;
|
|
115
|
+ }
|
|
116
|
+ // 边界判断
|
|
117
|
+ if (left < 0 - offsetpx) {
|
|
118
|
+ offset = 0 - offsetpx;
|
|
119
|
+ } else {
|
|
120
|
+ if (offset > 0) {
|
|
121
|
+ offset = "+=" + divwidth;
|
|
122
|
+ offleft = offleft;
|
|
123
|
+ } else {
|
|
124
|
+ offset = "-=" + divwidth;
|
|
125
|
+ offleft = offset;
|
|
126
|
+ }
|
|
127
|
+ }
|
99
|
128
|
|
|
129
|
+ list.animate({ left: offset }, 300, function () {
|
|
130
|
+ if (left > -200) {
|
|
131
|
+ list.css("left", (0 - offset) * len);
|
|
132
|
+ }
|
|
133
|
+ });
|
|
134
|
+}
|
100
|
135
|
//亮起小圆点
|
101
|
136
|
function showButton() {
|
102
|
137
|
//当前图片的小圆点亮起,其他小圆点不亮
|
103
|
|
- console.log(index, "gaoliang");
|
104
|
138
|
buts
|
105
|
139
|
.eq(index - 1)
|
106
|
140
|
.addClass("active")
|
|
@@ -116,6 +150,9 @@ $(".develop_container").bind("mouseleave", () => {
|
116
|
150
|
});
|
117
|
151
|
// 鼠标离开图片区域时,轮播继续
|
118
|
152
|
function play() {
|
|
153
|
+ if (datalist.length <= 5) {
|
|
154
|
+ return;
|
|
155
|
+ }
|
119
|
156
|
timer = setTimeout(function () {
|
120
|
157
|
next.trigger("click");
|
121
|
158
|
play();
|
|
@@ -124,11 +161,16 @@ function play() {
|
124
|
161
|
|
125
|
162
|
//鼠标进入图片区域时,停止轮播
|
126
|
163
|
function stop() {
|
127
|
|
- clearTimeout(timer);
|
|
164
|
+ if (timer) {
|
|
165
|
+ clearTimeout(timer);
|
|
166
|
+ }
|
128
|
167
|
}
|
129
|
168
|
|
130
|
169
|
// 右按钮点击事件
|
131
|
170
|
next.bind("click", function () {
|
|
171
|
+ if (datalist.length <= 5) {
|
|
172
|
+ return;
|
|
173
|
+ }
|
132
|
174
|
// 判断当前是否在动画
|
133
|
175
|
if (list.is(":animated")) {
|
134
|
176
|
return;
|
|
@@ -137,36 +179,38 @@ next.bind("click", function () {
|
137
|
179
|
// 判断当前图片是否是最后一张
|
138
|
180
|
if (index == datalist.length) {
|
139
|
181
|
index = 1;
|
140
|
|
- console.log(222222);
|
141
|
182
|
offleft = 0;
|
142
|
183
|
list.animate({ left: 0 }, 300, () => {});
|
143
|
184
|
} else {
|
144
|
185
|
index += 1;
|
145
|
186
|
}
|
146
|
|
- console.log(offleft, "当前偏移量");
|
147
|
|
- console.log("you", index);
|
148
|
187
|
animate(0 - divwidth);
|
|
188
|
+ showdata(index - 1);
|
149
|
189
|
showButton();
|
150
|
190
|
stop();
|
151
|
191
|
});
|
152
|
192
|
|
153
|
193
|
// 左按钮事件
|
154
|
194
|
prev.bind("click", function () {
|
|
195
|
+ if (datalist.length <= 5) {
|
|
196
|
+ return;
|
|
197
|
+ }
|
155
|
198
|
// 判断当前是否在动画
|
156
|
199
|
if (list.is(":animated")) {
|
157
|
200
|
return;
|
158
|
201
|
}
|
159
|
|
- console.log(index);
|
|
202
|
+
|
160
|
203
|
// 判断当前图片是否是第一张
|
161
|
204
|
if (index == 1) {
|
162
|
205
|
index = datalist.length;
|
163
|
206
|
} else {
|
164
|
207
|
index -= 1;
|
165
|
208
|
}
|
166
|
|
- console.log("zuo", index);
|
167
|
|
- console.log(offleft, "当前偏移量");
|
|
209
|
+
|
168
|
210
|
animate(divwidth);
|
|
211
|
+ showdata(index - 1);
|
169
|
212
|
showButton();
|
|
213
|
+
|
170
|
214
|
stop();
|
171
|
215
|
});
|
172
|
216
|
|
|
@@ -179,23 +223,20 @@ buts.each(function () {
|
179
|
223
|
}
|
180
|
224
|
// 获取属性
|
181
|
225
|
var myIndex = parseInt($(this).attr("index"));
|
182
|
|
- console.log(myIndex);
|
|
226
|
+ if (myIndex == index) {
|
|
227
|
+ return;
|
|
228
|
+ }
|
183
|
229
|
//计算偏移量
|
184
|
230
|
var offset = (0 - divwidth) * (myIndex - index);
|
185
|
|
- if (myIndex <= 2) {
|
186
|
|
- offset = 0;
|
187
|
|
- console.log(myIndex, 33333);
|
188
|
|
- }
|
189
|
|
- console.log(offleft, "当前偏移量");
|
190
|
|
- animate(offset);
|
191
|
|
-
|
|
231
|
+ animates(offset);
|
|
232
|
+ // list.animate({ left: -360 });
|
192
|
233
|
//切换后,更新当前的偏移量
|
193
|
234
|
index = myIndex;
|
194
|
|
-
|
|
235
|
+ showdata(index - 1);
|
195
|
236
|
showButton();
|
196
|
237
|
});
|
197
|
238
|
});
|
198
|
|
-
|
|
239
|
+showdata(0);
|
199
|
240
|
container.hover(stop, play);
|
200
|
241
|
|
201
|
242
|
play();
|