(function($){ /* 回到購買處 */ $('.gobuy').on('click',function(){ var tol = $(window).height(); console.log(tol); var buy = $('.button-line').offset().top-tol+50 ; $("html,body").scrollTop(buy); }); //按下討論按鈕跳到討論標題 $(".Go_Comment_Title").click(function(e){ e.preventDefault(); $('html, body').animate({scrollTop: parseInt($("#Comment").offset().top)-30}, 500); }); /*為JQ添加naturalWidth()和naturalHeight()方法,抓取圖片原始尺寸*/ var props = ['Width', 'Height'], prop; while (prop = props.pop()) { (function (natural, prop) { $.fn[natural] = (natural in new Image()) ? function () { return this[0][natural]; } : function () { var node = this[0], img, value; if (node.tagName.toLowerCase() === 'img') { img = new Image(); img.src = node.src, value = img[prop]; } return value; }; }('natural' + prop, prop.toLowerCase())); } /*評論預覽商品圖*/ $(".pic-box").on("click",".pic-over",function(){ var _this = $(this), pic_src = _this.find("img").attr('src'); _this.parents(".pic-box").find(".click").removeClass("click"); _this.addClass("click"); _this.parents(".pic-box").find(".pic-viewer").addClass("click") .find('img').attr({src: pic_src}); }); $('.pic-box').on('click', '.close', function(event) { var _this = $(this).parents(".pic-box"); _this.find(".pic-viewer").removeClass("click"); _this.find(".click").removeClass("click"); }); $('#preview').css('display','none'); $("article .recommend_l,article .history_l,article .other_l").owlCarousel({ nav : true, responsive:{ 0:{ items : 2 }, 480:{ items : 3 }, 768:{ items : 4 }, 1024:{ items : 5 } }, navText : ['',''] }); let productStep = '' let columnStep = '' $(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 //=========================================================== // ========================================================== // 相關專欄區塊調整 // ========================================================== const columnSlide = $('.relate-column') if($(this).width() > 1024 && columnStep !== 'desktop') { columnStep = 'desktop' columnSlide.each(function(i, ele) { if($(ele).data('owl.carousel')) { $(ele).data('owl.carousel').destroy() } if($(ele).children().length > 4) { $(ele).owlCarousel({ items: 4, margin: 15, slideBy: 'page', nav: true, dots: false, }) } }); } else if($(this).width() <= 1024 && $(this).width() > 768 && columnStep !== 'tablet') { columnStep = 'tablet' columnSlide.each(function(i, ele) { if($(ele).data('owl.carousel')) { $(ele).data('owl.carousel').destroy() } if($(ele).children().length > 3) { $(ele).owlCarousel({ items: 3, margin: 10, slideBy: 'page', nav: true, dots: false, }) } }); } else if($(this).width() <= 768 && columnStep !== 'mobile') { columnStep = 'mobile' columnSlide.each(function(i, ele) { if($(ele).data('owl.carousel')) { $(ele).data('owl.carousel').destroy() } }); } }) $(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) }); //=========================================================== // 放大鏡預覽翻頁到目前點選 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 //=========================================================== // 放大圖切換 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').find('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 zoonbox(){ var ImgBox,ImgBox_h,ImgBox_w,viewbox,viewbox_h,viewbox_w,viewbox_b,viewbox_r,preview,preview_img,scale_h,scale_w; // preview_str= '