/
__scripts.php
159 lines (132 loc) · 4.59 KB
/
__scripts.php
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
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin=" anonymous"></script>
<script>
// hide-nav //
$(window).scroll(function () {
let scrollTop = $(this).scrollTop();
if (scrollTop <= 150) {
$(".nav").removeClass('hide-nav');
} else {
$(".nav").addClass('hide-nav');
}
});
// menu //
$(".nav-list .dropdown>a").hover(function(){
$(this).closest(".dropdown").addClass('show');
})
$(".nav-list .dropdown").mouseleave(function(){
$(this).closest(".dropdown").removeClass('show');
})
$("#menuClickArea").click(function () {
$(this).closest(".menu").toggleClass('current');
})
$(".menu").mouseleave(function(){
$(this).removeClass('current');
$(this).find(".dropdown").removeClass('show');
})
$(".menu-list .dropdown>a").click(function(){
$(this).closest(".dropdown").toggleClass('show');
})
// btn-top //
let vh = $(window).height();
$("#goTop").css({
"visibility" : "hidden",
"opacity": "0"
})
$("#goTop").click(function () {
$("html").animate({
scrollTop: 0
})
});
$(window).scroll(function () {
let scrollTop2 = $(this).scrollTop();
// console.log(scrollTop)
if (scrollTop2 < vh) {
$("#goTop").css({
"visibility" : "hidden",
"opacity": "0"
})
}
else {
$("#goTop").css({
"visibility": "visible",
"opacity": "1",
"cursor": "pointer"
})
}
})
// footer
if ($(window).width() < 768) {
$(".bg-footer").attr("src","images/footer-bg-mobile.svg")
}
//-------------- SVG 變色 -------------//
jQuery('img.svg').each(function () {
var $img = jQuery(this);
var imgID = $img.attr('id');
var imgClass = $img.attr('class');
var imgURL = $img.attr('src');
jQuery.get(imgURL, function (data) {
// Get the SVG tag, ignore the rest
var $svg = jQuery(data).find('svg');
// Add replaced image's ID to the new SVG
if (typeof imgID !== 'undefined') {
$svg = $svg.attr('id', imgID);
}
// Add replaced image's classes to the new SVG
if (typeof imgClass !== 'undefined') {
$svg = $svg.attr('class', imgClass + ' replaced-svg');
}
// Remove any invalid XML tags as per http://validator.w3.org
$svg = $svg.removeAttr('xmlns:a');
// Check if the viewport is set, if the viewport is not set the SVG wont't scale.
if (!$svg.attr('viewBox') && $svg.attr('height') && $svg.attr('width')) {
$svg.attr('viewBox', '0 0 ' + $svg.attr('height') + ' ' + $svg.attr('width'))
}
// Replace image with new SVG
$img.replaceWith($svg);
}, 'xml');
});
// cart_count and cart_short_list
const cart_count = $('.cart_count');
const cart_short_list = $('.cart-short-list');
//將資料送到api取得結果
$.get('cart-handle.php', function(data) {
setCartCount(data); //將取得的結果送到function處理
}, 'json');
function setCartCount(data) {
let count = 0;
cart_short_list.empty(); //先清空再append新的內容
if (data && data.cart && data.cart.length) {
for (let i in data.cart) {
let item = data.cart[i];
let subtotal = item['price'] * item['qty']
count += item['qty'];
cart_short_list.append(`
<div class="nav-eachsock-list flex">
<div class="nav-img-product">
<img src="images/product/${item['img_ID']}-1.jpg" alt="">
</div>
<div class="nav-socks-nameNprice flex">
<h5 class="nav-socks-title">${item['product_name']}</h5>
<div class="qtyNprice flex">
<h5>× ${item['qty']}</h5>
<h5 class="nav-socks-price">NT$ ${subtotal}</h5>
</div>
</div>
</div>`)
}
cart_count.css('background', '#FF9685');
cart_count.text(count);
} else {
cart_short_list.append(`
<div class="nav-icon-empty-cart flex">
<img class="img-empty-cart" src="images/cart-empty.svg" alt="">
<h4 class="nav-empty-cart">購物車空空的。</h4>
</div>`)
cart_count.css('background', 'transparent');
cart_count.text('');
}
}
$('.a-cart').click(function() {
$('.box-cart-short').toggleClass('show')
})
</script>