$(document).ready(function(){
//商品內容
var file_Obj = new prod_file({
specUrl: '/activities/ajax/act9/ajax_get_item.php',
contBox: 'inner',
itemBox:'selectPopupBox',
specClass:'selectPopupBox-line',
});
file_Obj.init();
var hover_Obj = new prod_hover({
hoverTarget: ".pic",
productBox: ".productBox:not(.todaysale-end)"
})
//開啟購買跳窗
$('main').on('click','.Add_Button1,.index-buyButton,.selectbox-button',function(){
$('.selectPopupBox').html($(this).parents(".productBox").find(".Box_Data").html());
$('.selectPopupBox').addClass('is-show');
});
//頁面倒數
//與頂端倒數類似
var num = parseInt($(".act9-todaysale-countdown").data("second"),10),
_this = $(this),
pad = "00";
if(num < 86400){
//小於一天隱藏 "天"
$(".act9-todaysale-day-box , .day-colon").hide()
}
setInterval(function(){
num--;
if(num <= 0)
{
window.location.reload();
}
let num2 = 0
let day = Math.floor(num / 86400)
num2 = num % 86400
let hour = Math.floor(num2 / 3600)
num2 = num2 % 3600
let min = Math.floor(num2 / 60)
num2 = num2 % 60
let second = num2
$(".act9-todaysale-day-box").html(timeSplitToSingle(day,"d"));
$(".act9-todaysale-hour-box").html(timeSplitToSingle(hour,"h"));
$(".act9-todaysale-minute-box").html(timeSplitToSingle(min,"m"));
$(".act9-todaysale-second-box").html(timeSplitToSingle(second,"s"));
},1000);
//商品今日限定倒數
$(".todaySale").find(".sellbox").each(function(){
var num = parseInt($(this).find(".timerbox").attr("second"),10),
_this = $(this);
setInterval(function(){
num--;
if(num <= 0)
{
window.location.reload();
}
var hour = Math.floor(num/3600),
min = Math.floor((num - (hour*3600) )/60 ),
second = num - (hour*3600) - (min*60),
pad = '00';
_this.find(".timer").eq(0).html(pad.substring(hour.toString().length)+hour);
_this.find(".timer").eq(1).html(pad.substring(min.toString().length)+min);
_this.find(".timer").eq(2).html(pad.substring(second.toString().length)+second);
},1000);
});
//================
//filter start
//===============
var clickbutton=0;
$('.filter-button,.filterbox .close').on('click',function(){
clickbutton++;
if(clickbutton==1){
$('.filterbox').css({'top':'50px'});
}
if(clickbutton==2){
$('.filterbox').css({'top':'-100%'});
clickbutton=0;
}
//================
//filter end
//===============
});
});
function timeSplitToSingle(time,mode){
//沒2位數就補0
let timeStr = (time.toString().length < 2)? "0" + time.toString() : time.toString()
let timeHtml = ``
switch(mode){
case "d":
for(idx in timeStr){
timeHtml += `
${timeStr[idx]}
`
}
break;
case "h":
for(idx in timeStr){
timeHtml += `
${timeStr[idx]}
`
}
break;
case "m":
for(idx in timeStr){
timeHtml += `
${timeStr[idx]}
`
}
break;
case "s":
for(idx in timeStr){
timeHtml += `
${timeStr[idx]}
`
}
break
default:
return ;
}
return timeHtml
}