$(function(){ const orderSetting = { responsive:{ 0:{ items : 1 }, 480:{ items : 2 }, 800:{ items : 3 } }, nav : true, onRefresh : callback, margin: 10, } /* 使用者已選購區塊 */ var owl_main = $(".mainbox .orderSlide"); owl_main.owlCarousel(orderSetting); var owl_add = $(".addbox .orderSlide"); owl_add.owlCarousel(orderSetting); function callback(event){ setTimeout(function(){ $('.hidebox').animate({'opacity':1}).removeClass('hidebox'); }, 300); } /* 加購商品選購效果 */ $('article > .content-add ').on('click','.button1',function(){ var img = $(this).parents('.productBox'), img_src = img.find('img').attr('src'), img_title = img.find('.title').html(), img_price = img.find('.font-red').html(), img_id = $(this).attr("SID"), img_num = img.find('.amountBox').val(); if(img_num == '無庫存'){ return false; } var html = '
'+img_title+'
'+img_price+'
刪除
'; var smailBox = $('.addbox .orderSlide'), smailBox_top = smailBox.offset().top, smailBox_left = smailBox.offset().left, smailBox_width = smailBox.width()/4, smailBox_height = smailBox.height()-20; for(var i=0;i
'+img_title+'
NT$'+img_price+'
刪除
'; var now_order = $('.mainbox .'+ img_class); var change_n = n-now_order.length; if(change_n>0){ for(var i=0;i 769 && change!=960 ){ // change = 960; // moreview = true; // smallPicBox(); // // zoonbox(); // videoBox(); // }else if(_window.width() <= 768 && change!= 768){ // change = 768; // var this_sid = $(".colorbox").eq(0).attr("sid"); // if(!this_sid){ // this_sid = $(".act5_to_cart").attr("sid"); // } // $.get('/activities/ajax/activitiesView_moblie.php',{sid:this_sid}, function(data,status){ // $('.productView').html(data) // $('.productImg').owlCarousel({ // loop : false, // items : 1, // nav : true, // }); // $('.productImg').on('changed.owl.carousel',function(e){ // var num = e.item.index; // if(document.getElementById("Video")){ // if($(".productView").find(".owl-item").eq(num).find("#Video").attr("class")){ // $("#big_picture").hide(); // document.getElementById("Video").play(); // }else{ // $("#big_picture").show(); // document.getElementById("Video").pause(); // } // } // }); // }); // }; // $('article').on('click','.open-preview',function(){ // var nowitem = $('.productImg .active').prevAll('.owl-item').length-2; // $('article .previewbox').css('display','block') // .find('img').eq(nowitem).css('display','block'); // }); // $('article').on('click','.close',function(){ // $('article .previewbox').removeAttr('style') // .find('img').removeAttr('style'); // }); // _window.on('resize',function(){ // if(_window.width() > 768 && change != 960){ // change = 960; // $('.productView .moreview').removeAttr('style'); // $.get('/activities/ajax/activitiesView_pc.php',{sid:$(".colorbox").eq(0).attr("sid")}, function(data,status){ // $('.productView').html(data); // change = 960; // moreview = true; // smallPicBox(); // // zoonbox(); // videoBox(); // }); // }else if(_window.width() <= 768 && change != 768){ // change = 768; // var this_sid = $(".colorbox").eq(0).attr("sid"); // if(!this_sid){ // this_sid = $(".act5_to_cart").attr("sid"); // } // $.get('/activities/ajax/activitiesView_moblie.php',{sid:this_sid}, function(data,status){ // $('.productView').html(data) // $('.productImg').owlCarousel({ // loop : false, // items : 1, // nav : true, // }); // }); // $('.productImg').on('changed.owl.carousel',function(e){ // var num = e.item.index; // if(document.getElementById("Video")){ // if($(".productView").find(".owl-item").eq(num).find("#Video").attr("class")){ // $("#big_picture").hide(); // document.getElementById("Video").play(); // }else{ // $("#big_picture").show(); // document.getElementById("Video").pause(); // } // } // }); // }; // }); }); ;(function($) { let productStep = '' $(window).on('resize', function(e) { // ========================================================== // 商品圖片展示區塊 // ========================================================== const mainWrap = $(".productView") const previewWrap = $('.productImg') if($(this).width() > 1024 && productStep !== 'desktop') { productStep = 'desktop' if(previewWrap.data('owl.carousel')) { previewWrap.data('owl.carousel').destroy() } if($(".moreview .picitem").length > 5){ mainWrap.find(".moreview").addClass('with-padding').owlCarousel({ loop:false, items: 5, nav: true, dots: false, margin: 7, }).on('mouseenter','.owl-item', function(e) { thumbnailChange(this, mainWrap) }).on('click','.owl-item', function(e) { thumbnailChange(this, mainWrap) }) }else{ mainWrap.find(".moreview").on('mouseenter','.picitem', function() { thumbnailChange(this, mainWrap) }).on('click','.picitem', function() { thumbnailChange(this, mainWrap) }) } } else if($(this).width() <= 1024 && productStep !== 'tablet') { productStep = 'tablet' if(mainWrap.find(".moreview").data('owl.carousel')) { mainWrap.find(".moreview").data('owl.carousel').destroy() } previewWrap.owlCarousel({ items: 1, margin: 10, nav: true, dots: false, }).on('translated.owl.carousel', function(e) { const itemIndex = $(this).find('.owl-item.active').index() $(this).find('.picbox').removeClass('now') $($(this).find('.picbox')[itemIndex]).addClass('now') //zoomPictureCheck(this) }) } // ========================================================== // 商品放大鏡位置調整 // ========================================================== if($(this).width() > 1024) { const offsetValue = $('.productView').width() - $('.open-preview').height() - 10 $('.open-preview').css('top', offsetValue) } else { $('.open-preview').removeAttr('style') } }) //=========================================================== // 放大鏡預覽可換頁 start //=========================================================== $('.previewbox .preview-content').owlCarousel({ items: 1, nav: true, dots: false }) //=========================================================== // 放大鏡預覽可換頁 end //=========================================================== //=========================================================== // 放大鏡預覽翻頁到目前點選 start //=========================================================== function zoomPictureSwitch(){ let bodyWidth = document.body.clientWidth let activeIndex = 0 if(bodyWidth > 1024){ activeIndex = $('.productImg .now').index() }else{ activeIndex = $('.productImg .active').index() } $('.previewbox .preview-content').trigger('to.owl.carousel',[activeIndex,0,true]) } //=========================================================== // 放大鏡預覽翻頁到目前點選 end //=========================================================== $(window).trigger('resize') // 放大圖開關 $('article').on('click','.open-preview',function(){ zoomPictureSwitch() overflowTop = $(window).scrollTop() $('#wrapper').addClass('overflow-hidden').scrollTop(overflowTop - ($('body').innerHeight() - $('body').height())) $('article .previewbox').css('display', 'block') }); $('article').on('click','.close',function(){ $('article .previewbox').removeAttr('style') $('#wrapper').removeClass('overflow-hidden').scrollTop(0) $(window).scrollTop(overflowTop) }); // 放大圖切換 function zoomPictureCheck(checkObj) { const activeItem = $(checkObj).find('.picbox.now')[0] const newAry = [] $(checkObj).find('.picbox').each(function(index, item) { newAry.push(item) }); const activeIndex = newAry.indexOf(activeItem) $('.previewbox').children('img').eq(activeIndex).css('display', 'block').siblings('img').removeAttr('style') } // 縮圖對應大圖展示 function thumbnailChange(thisItem, mainWrap) { const nowIndex = $(thisItem).index(); mainWrap.find('.picbox').eq(nowIndex).addClass('now').siblings('.picbox').removeClass('now') mainWrap.find('.picitem').removeClass('now') $(mainWrap.find('.picitem')[nowIndex]).addClass('now') //zoomPictureCheck(mainWrap) } })($) /*影片效果*/ function videoBox(){ //影片控制 $(".moreview").on('click','.video_control',function(){ var video = document.getElementById("Video"); if(video.paused){ $(this).addClass('fa-pause').removeClass('fa-play'); video.play(); }else{ $(this).addClass('fa-play').removeClass('fa-pause'); video.pause(); } }); //影片預覽圖 if(document.getElementById("Video")){ document.getElementById("Video").oncanplay=function(){ var video = $("#Video").get(0); var canvas = document.getElementById("video_review"); canvas.getContext('2d').drawImage(video, 0, 0, 66, 92); }; } }