//立即購買_取得商品詳細資料 function get_prod_item(SID){ $.ajax({ url:"/module/ajax/ajax_get_pop_prod_item-p.php", type:"POST", cache:false, async:false, dataType:"json", data:{SID:SID}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Size_Sel==''){ if(d.Stock>0){ add_to_cart(SID,1); }else{ alert(_jsLang.商品庫存不足); } }else{ $(".buypop-title").html(d.Name); $('.buypop-word').html(d.Name_Sub); $('.buypop-picbox').html(d.Pic_Path); $('.buypop-price').html('NT$'+d.Price1); $('.buypop-selectbox').html(d.Size_Sel); if(d.Stock>0){ $('.text-smail').val(1); }else{ $('.buypop-buttonbox').html(_jsLang.商品庫存不足); } $('.text-smail').attr('max',d.Stock); $('.buypop-button').attr('sid',d.ID); $('.buypopbox').css('display','flex'); } } }); } //立即購買_加入購物車 function add_to_cart(SID,num){ $.ajax({ url:"/ajax/ajax_add_to_cart.php", type:"POST", cache:false, async:false, data:{SID:SID, num:num, webcacheno:$('#webcacheno').val()}, dataType: 'json', error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Stock && d.Stock != 'null'){ d.Stock = (d.Stock>20)?'20':d.Stock; if(d.Stock>0){ $('.text-smail').val(1); }else{ $('.text-smail').val(0); } $('.text-smail').attr('max',d.Stock); } if(d.Alert == 'OK'){ if(d.GA && typeof ga == 'function') { for(var key in d.GA) { ga('ec:addProduct',d.GA[key]); } ga('ec:setAction','add'); ga('send','event','購物車','加入購物車'); } if(d.GA_conversion && typeof gtag == 'function') { gtag('event', 'conversion', {'send_to':d.GA_conversion}); } if(d.FBQ){eval(d.FBQ)} window.dataLayer = window.dataLayer || []; dataLayer.push({ 'event' : 'productAddToCart', 'ecommerce' : { 'currencyCode' : 'TWD', 'add' : { 'products' : [ { 'name' : d.adGeek_Data['name'], 'en_name' : '', 'id' : d.adGeek_Data['id'], 'category' : d.adGeek_Data['category'][0], 'price' : d.adGeek_Data['price'], 'specification' : d.adGeek_Data['specification'][0], 'quantity' : num } ] } } }); $.ajax({ url:"/ajax/ajax_get_cart.php", type:"POST", async:false, cache:false, data:{Type:'Prod',ID:SID,Act:'Add'}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ //$(".shopping-cartbox").css('display','none'); $("#Header_Shopcart").html(d); $("#Header_Shopcart").parent(".shopping-cartbox").animate({'opacity':1,'maxHeight':'999px'}).css('z-index','100'); setTimeout(function(){ $("#Header_Shopcart").parent(".shopping-cartbox").animate({'maxHeight':'0px','opacity':0},function(){ $(this).removeAttr('style'); $(".shopping-cartbox").removeAttr('style'); }); },3000); } }) }else{ alert(d.Alert); } } }); } $(document).ready(function () { const _window = $(window); //立即購買 $('body').on('click','.index-buyButton',function(){ var SID = $(this).attr('sid'); if(SID){ get_prod_item(SID); } }); //立即購買_關閉 $('.buypop-close').on('click',function(){ $('.buypopbox').removeAttr('style'); }); //立即購買_規格下拉選單 $(".buypop-selectbox").on('change',".color-select, .size-select",function(){ var SID = $(this).val(); if(SID){ get_prod_item(SID); } }); //立即購買_加入購物車按鈕 $(".buypop-buttonbox").on("click",".buypop-button",function(){ var _item = $(this).parents(".buypop-buttonbox"), SID = $(this).attr('sid') || 0, num = _item.find(".amountBox").val() || 0; if(SID == 0){ alert(_jsLang.請選擇尺寸或規格); //errorbox(); }else if(num ==0){ alert(_jsLang.請選擇數量); //errorbox(); }else{ add_to_cart(SID,num); } }); //立即購買_數量- $('.buypop-num').on('click','.fa-minus',function(){ var now_num = $('.amountBox').val(); now_num = parseInt(now_num); if(now_num>1){ $('.amountBox').val(now_num-1); } }); //立即購買_數量+ $('.buypop-num').on('click','.fa-plus',function(){ var now_num = $('.amountBox').val(); var max_num = $('.amountBox').attr('max'); now_num = parseInt(now_num); max_num = parseInt(max_num); if(now_num < max_num){ $('.amountBox').val(now_num+1); } }); //立即購買_輸入 $('.amountBox').keyup(function(){ var now_num = $('.amountBox').val(); var max_num = $('.amountBox').attr('max'); now_num = parseInt(now_num); max_num = parseInt(max_num); $('.amountBox').val(now_num); if(now_num>max_num){ $('.amountBox').val(max_num); } if(now_num<1){ $('.amountBox').val(1); } if(isNaN(now_num)){ $('.amountBox').val(1); } }); // 限時商品 $('.todaySell-silde').owlCarousel({ responsive:{ 0:{ items : 1 }, 480:{ items : 2 }, 960:{ items : 3 } }, nav: true, navText: ['',''], dots: false, }); }); // ========================================================== // 紅眼廣告 // ========================================================== ;(function($) { // 首頁主廣告 if($("#slideshow .slide-item").length > 1){ $("#slideshow").owlCarousel({ loop : true, items : 1, nav : false, navText : ['',''], dots:true, animateOut:'fadeOut', autoplay:true, autoplayTimeout:9500, autoplayHoverPause: true, autoaplaySpeed: 1000, }); } // 首頁主廣告 if($(".slideshow-004").length != 0){ var AID = $(".today-wrapper").find(".slide-item").eq(0).attr("AID"); $("#Today_Title_Url").attr("href","/activities9/"+AID) $(".today-wrapper").owlCarousel({ loop : false, responsive:{ 0:{ items : 2 }, 660:{ items : 3 }, 1024:{ items : 1 } }, nav : false, navText : ['',''], dots:true, autoplay:true, navSpeed:1000, autoplayTimeout:8000, autoplaySpeed:1000, }); $(".today-wrapper").on('changed.owl.carousel',function(d){ var AID = $(".today-wrapper").find(".slide-item").eq(d.item.index).attr("AID"); $("#Today_Title_Url").attr("href","/activities9/"+AID) }); } })($) // ========================================================== // 最新消息跑馬燈 // ========================================================== ;(function($) { if($('.news-marquee').length) { $('.news-marquee').each(function(i, ele) { if($(ele).children().length > 1) { $(ele).owlCarousel({ autoplay: true, autoplayHoverPause: true, autoplaySpeed: 1500, autoplayTimeout: 5000, dots: false, items: 1, loop: true, margin: 10, nav: false, navText: ['', ''], }) } }) } })($) // ========================================================== // 熱銷商品、新品上市、今日限定輪播、推薦主題商品 // ========================================================== ;(function($) { const slideTarget = $('.oneline-fiveitem-01, .new-arrivals, .todaySale, .tags-001').find('.wrapper') slideTarget.owlCarousel({ navText: ['',''], nav: true, dots: false, responsive: { 0: { items: 2, margin: 10, }, 660: { items: 3, margin: 0, }, 992: { items: 4, margin: 5, } }, }); })($) // ========================================================== // LOOKBOOK 背景滾動 // ========================================================== ;(function($) { let winHeight = $(this).outerHeight(true) $(window).on('resize', function(e) { winHeight = $(this).outerHeight(true) }) $(window).on('scroll', function(e) { winHeight = $(this).outerHeight(true) const winTop = $(this).scrollTop() $('.lookbook .picbox').each(function(i, ele) { const eleTop = $(ele).parent('.lookbook').offset().top // console.log((winTop - eleTop) / winHeight / 2 - 0.25) $(ele).css({ top: (winTop - eleTop) / 2 - winHeight / 4 }) }) }) })($) // ========================================================== // 影音專區 影片切換 // ========================================================== ;(function(window, document, $) { if($('.swiper-box').length) { const videoSlide = new Swiper('.swiper-box', { direction: 'vertical', navigation: { nextEl: '.swiper-next', prevEl: '.swiper-prev', }, breakpoints: { 768: { slidesPerView: 3, spaceBetween: 10, }, 1200: { slidesPerView: 4, spaceBetween: 20, }, }, }) } if($('.video-wrapper').length) { // 影片切換 $('.video-wrapper').on('click', '.video-link', function(e) { e.preventDefault() const changeTarget = $(this).parents('.video-wrapper').find('.video-preview') const VID = $(this).attr('data-vid') jQuery.ajax({ url: '/module/ajax/ajax_get_video_prod-p.php', type: 'POST', dataType: 'json', async: true, data: { 'VID': VID, }, }).done(function(res) { console.log(res); const {Name, Url, VideoID, ProdPrice} = res const videoPath = `https://www.youtube.com/embed/${VideoID}?theme=light;showinfo=0;rel=0&autoplay=1;enablejsapi=1` let appendStr = '' if(Name) { appendStr += `