-
Notifications
You must be signed in to change notification settings - Fork 0
/
fontPage.js
72 lines (63 loc) · 1.77 KB
/
fontPage.js
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
//banner slide功能
$(function () {
let divWidth = $("#slider").width();
//div寬度
let imgCount = $("#slider-content li").length;
//圖片的總長度
for (let i = 0; i < imgCount; i++) {
$("#contentButton").append(`<li></li>`);
//有幾張圖片就要加幾個小圓點
}
$("#contentButton li:first").addClass("clicked");
$("#slider-content li").width(divWidth); // li 的寬度
$("#slider-content").width(divWidth * imgCount); // ul 的寬度
let index = 0;
let timer = setInterval(moveToNext, 3000);
$("#contentButton li").click(function () {
clearInterval(timer);
index = $(this).index();
$("#slider-content").animate({
left: divWidth * index * -1,
});
//點擊黑點變綠點
$(this).addClass("clicked");
$("#contentButton li").not(this).removeClass("clicked");
timer = setInterval(moveToNext, 3000);
});
function moveToNext() {
if (index < imgCount - 1) {
index++;
} else {
index = 0;
}
$("#slider-content").animate({
left: divWidth * index * -1,
});
$(`#contentButton li:eq(${index})`).addClass("clicked");
$("#contentButton li").not(`:eq(${index})`).removeClass("clicked");
}
});
//推薦slider
$(function () {
let saleCard = $(`.card-slide`);
let curIndex = 0;
$(`#left`).click(function () {
curIndex--;
saleCard.css({ left: -curIndex * 210 });
if (curIndex === 0) {
$(`#left`).attr("disabled", true);
} else {
$(`#right`).attr("disabled", false);
}
});
$(`#right`).click(function () {
curIndex++;
saleCard.css({ left: -curIndex * 210 });
$(`#left`).attr("disabled", false);
if (curIndex === 3) {
$(`#right`).attr("disabled", true);
} else {
$(`#left`).attr("disabled", false);
}
});
});