$(document).ready(function () { //立即購買 $('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); } }); //立即購買_取得商品詳細資料 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'){ window.omnichatTracker.push(['event','add_to_cart', { "items": [d.GA] }]); if(d.GA4 && typeof gtag == 'function') { for(var key in d.GA4) { gtag("event","add_to_cart",{ "items":d.GA4 }); } } if(d.FBQ) { eval(d.FBQ); } if(d.Line){ eval(d.Line); } $.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); } } }); } // 首頁主廣告 if($("#slideshow .slide-item").length>=1){ $("#slideshow").owlCarousel({ loop : true, items : 1, nav : false, navText : ['',''], dots:true, autoplay:true, animateOut:'fadeOut', autoplayTimeout:9500, }); } // 首頁主廣告 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({ responsive:{ 0:{ items : 2, margin: 10 }, 660:{ items : 3, margin: 10 }, 1024:{ items : 4, }, 1025:{ 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) }); } // ========================================================== // 調整首頁 .owl-carousel .owl-nav 在桌機 (> 1024px) 時 // 箭頭相對於圖片垂直置中 // ========================================================== function verticalAlignMiddle(jqElement) { const target = jqElement; if(target.length) { const targetPic = target.find('img'); // 圖片高度 // ============================= const picHeight = targetPic.outerHeight(); // 圖片相對於 .owl-carousel 的高度差 // ============================= const picOffsetY = targetPic.offset().top - target.offset().top; // 設定 .owl-nav top 的值 // ============================= const topValue = picOffsetY + picHeight / 2; target.find('.owl-nav').css({ top: topValue }); } } // ========================================================== // 銷售排行 top sale 廣告輪播 // ========================================================== let topSale = $('.topsale-list'); topSale.owlCarousel({ nav: true, responsive: { 0: { dots: true, items: 2, margin: 20 }, 481: { dots: true, items: 2, margin: 20 }, 769: { dots: true, items: 3, margin: 30 }, 1025: { dots: false, items: 4, margin: 40 }, }, stagePadding: 10 }); setTimeout(function(){ topSale.fadeIn('slow',function(){ $(this).css({'opacity':1}); }); },1000) // ========================================================== // 新品上市 new arrivals 廣告輪播 // ========================================================== let newArrival = $('.new-products'); newArrival.owlCarousel({ nav: true, responsive: { 0: { dots: true, items: 2, margin: 20 }, 481: { dots: true, items: 2, margin: 20 }, 769: { dots: true, items: 3, margin: 30 }, 1025: { dots: false, items: 4, margin: 40 }, }, stagePadding: 10 }); // ========================================================== // 首頁影音列表輪播設定 // ========================================================== let videoList = $('.video-list'); videoList.owlCarousel({ margin: 20, nav: true, responsive: { 0: { dots: true, items: 2, }, 481: { dots: true, items: 3, }, 769: { dots: true, items: 4, }, 1025: { dots: false, items: 5, }, }, }); var _window = $(window); if(_window.width() <= 768){ $('.video_listWrapper').owlCarousel({ loop : true, // items : 5, responsive:{ 0:{ items : 3 }, }, margin:5, merge:true, nav :false, navText : ['',''], dots:true, }); } // 限時商品 $('.video-silde').owlCarousel({ // loop : true, // items : 5, responsive:{ 0:{ items : 1 }, 660:{ items : 3 } }, nav : true, navText : ['',''], }); // IG $('.igpicbox-wrapper').owlCarousel({ // loop : true, margin:10, responsive:{ 0:{ stagePadding:50, items : 2 }, 660:{ stagePadding:60, items : 3 }, 1024:{ stagePadding:80, items : 4 }, 1300:{ stagePadding:100, items : 5 } }, loop:true, dots:false, nav : true, navText : ['',''], }); setTimeout(function(){ $('#slide_new').fadeIn('slow',function(){ $(this).css({'opacity':1}); }); },1000) // 新品登場 $('#slide_new').owlCarousel({ loop : true, // items : 5, responsive:{ 0:{ items : 2 }, 660:{ items : 2 }, 1024:{ items : 5 } }, nav : true, navText : ['',''] }); setTimeout(function(){ $('#slide_new').fadeIn('slow',function(){ $(this).css({'opacity':1}); }); },1000) // 今日限定 $('.todaySale .wrapper').owlCarousel({ // loop : true, // items : 5, responsive:{ 0:{ items : 2, nav :false, dots:true, margin:5, }, 660:{ items : 3, nav :false, dots:true, margin:10, }, 1024:{ items :4, nav :false, dots:true, }, 1300:{ items :4, nav :true, dots:false, } }, navText : ['',''] }); var _window = $(window); if(_window.width() >= 660){ // 推薦商品 $('.tags-001 .itembox').owlCarousel({ // items : 5, responsive:{ 0:{ items : 2 }, 660:{ items : 3 }, 860:{ items : 4 } }, nav :true, margin:5, navText : ['',''] // navText : ['',''] }); } // ========================================================== // 專題文章輪播 // ========================================================== let columnList = $('.columnBaike-list'); columnList.owlCarousel({ margin: 20, nav: true, responsive: { 0: { dots: true, items: 1, }, 481: { dots: true, items: 2, }, 661: { dots: true, items: 2, }, 1025: { dots: false, items: 3, }, }, }); //首頁專題 $(".lookbook .picbox").owlCarousel({ loop : true, items : 1, nav : true, navText : ['',''], autoplay:true, autoplayTimeout:5000, }); //試用評價 $('.review-001 .warpper').owlCarousel({ loop : true, // items : 5, responsive:{ 0:{ items : 2, nav :false, dots:true, }, 660:{ items : 5, nav :false, dots:true, }, 1300:{ items : 5, nav :true, dots:false, } }, navText : ['',''], }); // var owl =$('.picbox'); // $('.picbox').owlCarousel(); $('.picbox').on('translated.owl.carousel',function(event){ var id = $(this).find('.active').eq(0).find('.pic-item').attr('did'); ajax_topic_content(id); }); function ajax_topic_content(topic_id){ $.ajax({ url:"/module/ajax/ajax_get_topic_content-p.php", type:"POST", cache:false, async:false, dataType:"json", data:{ID:topic_id}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ $("#topic_content").html(d.Content); } }); } // ========================================================== // 啟動箭頭位置校正 // ========================================================== $(window).on('resize' , function(e) { if($(this).width() > 1024) { verticalAlignMiddle(topSale); verticalAlignMiddle(newArrival); verticalAlignMiddle(videoList); verticalAlignMiddle(columnList); } }) $(window).trigger('resize') }); // 首頁跳窗 setTimeout(function(){ $('.pop_block').fadeOut(300); },8000) // ========================================================== // autoWidth slider // ========================================================== $(function() { // $(".carousel-1").owlCarousel({ // responsive: { // 0: { // autoWidth: true, // nav: false, // dots: false // }, // 481: { // autoWidth: false, // loop: true, // margin: 0, // nav : true, // dots:false, // navText: ['', ''], // } // } // }); // $(".carousel-2").owlCarousel({ // responsive: { // 0: { // autoWidth: true, // nav: false, // dots: false // }, // 481: { // autoWidth: false, // loop: true, // margin: 20, // nav : true, // dots:false, // navText: ['', ''], // } // } // }); $(window).on('resize', function(e) { // if($(window).width() > 480){ $(".carousel-1").owlCarousel({ loop: true, margin: 0, pagination : false, nav : true, dots:false, navText: ['', ''], responsiveClass: true, }); $(".carousel-2").owlCarousel({ loop: true, margin: 20, pagination : false, nav : true, dots:false, navText: ['', ''], responsiveClass: true, }); // } else { // $(".carousel-1, .carousel-2").trigger('destory.owl.carousel') // } }) $(window).trigger('resize') }) // ========================================================== // 鎖定重新整理 // ========================================================== ;(function(window, document, $) { function log(obj) { console.log(obj) } let startY = 0 document.body.addEventListener('touchstart', function(e) { const target = e.targetTouches[0] startY = target.clientY }, { passive: false }) document.body.addEventListener('touchmove', function(e) { const target = e.targetTouches[0] const transY = target.clientY - startY if(transY > 0 && $('.header-01').offset().top <= 0 && !$('.nav-bg').hasClass('open-nav')) { e.preventDefault(); } }, { passive: false }) let touchStartHandler, touchMoveHandler, touchPoint; // Only needed for touch events on chrome. if ((window.chrome || navigator.userAgent.match("CriOS")) && "ontouchstart" in document.documentElement) { touchStartHandler = function() { // Only need to handle single-touch cases touchPoint = event.touches.length === 1 ? event.touches[0].clientY : null; }; touchMoveHandler = function(event) { var newTouchPoint; // Only need to handle single-touch cases if (event.touches.length !== 1) { touchPoint = null; return; } // We only need to defaultPrevent when scrolling up newTouchPoint = event.touches[0].clientY; if (newTouchPoint > touchPoint && $('.header-01').offset().top <= 0 && !$('.nav-bg').hasClass('open-nav')) { event.preventDefault(); } touchPoint = newTouchPoint; }; document.addEventListener("touchstart", touchStartHandler, { passive: false }); document.addEventListener("touchmove", touchMoveHandler, { passive: false }); } })(window, document, $)