const model = require('modules/module.js'); (function($){ /* 回到購買處 */ $('.gobuy').on('click',function(){ var tol = $(window).height(); // console.log(tol); var buy = $('.button-line').offset().top-tol+50 ; $("html,body").scrollTop(buy); }); /*為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"); }); /*上方banner廣告圖*/ $(".top_productbox").owlCarousel({ loop : false, responsive:{ 0:{ items : 2 }, 320:{ items : 3 }, 480:{ items : 6 }, 660:{ items : 8 }, 768:{ items : 9 }, 1023:{ items : 10 } }, nav : true, }); $('#preview').css('display','none'); $("article .recommend_l,article .history_l,article .other_l").owlCarousel({ nav : true, margin : 15, responsive:{ 0:{ items : 2 }, 480:{ items : 3 }, 768:{ items : 4 }, 1024:{ items : 5 } }, }); setTimeout(function(){ $("article .recommend_l,article .history_l,article .other_l").fadeIn('slow',function(){ $(this).css({'opacity':1}); }); },1000) var _window = $(window); var change = 0; var change_1023 = 0; var moreview = false; //關閉跳窗 $(".inner").on('click','.close, .add_to_cart',function(){ $(".selectPopupBox").removeClass('is-show'); }); $('article').on('click','.open-preview',function(){ var nowitem = $('.productImg .active').prevAll('.owl-item').length; $('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.trigger('resize'); }(jQuery)); $('#Go_Comment').click(function(){ $('#Go_Comment2').addClass('in-active'); $('html,body').animate({ scrollTop:$('#Go_Comment2').offset().top},{duration:500,easing:"swing"}); return false; }) // ========================================================== // 桌機版商品跳窗 // ========================================================== $(function() { $('.js-smartPhoto').SmartPhoto({nav: false}); }) // ========================================================== // 靜態頁跳窗 ajax // ========================================================== $(function() { const $wrap = $('body'); function popupClose() { $wrap.find('.popupWrapper').removeClass('in-open'); $('popupBlock').empty(); $wrap.removeClass('popupBox-active'); } $wrap.on('click', '.popupLink', function(e) { const filter = $(this).data('filter'); const url = $(this).data('src'); $wrap.find('.popupWrapper').addClass('in-open'); $wrap.addClass('popupBox-active'); }) $wrap.on('click', '.popupCloser', function(e) { popupClose(); }) $wrap.on('click', '.popupWrapper', function(e) { if(e.target === e.currentTarget) { popupClose(); } }) }) // ========================================================== // 「商品問與答」連動觸發效果 // ========================================================== $(function() { $('body').on('click', '#productFaq', function(e) { e.preventDefault() const target = $(this).attr('href') const targetY = $(target).offset().top; const headerHeight = $('.header-01').outerHeight() - $('.marquee-wrapper').outerHeight() $(target).addClass('in-active') $('html, body').animate({ scrollTop: targetY - headerHeight }, 500) }) }) // ========================================================== // 手機版開啟輪播功能 // ========================================================== var breakPoint = 'desktop'; $(function() { $(window).on('resize', function() { const target = $('.product-img-gallery'); if ($(window).width() < 1025 && breakPoint !== 'mobile') { breakPoint = 'mobile' target.show(); const cloneGallery = target.clone().addClass('owl-carousel Delete_When_Update') target.after(cloneGallery); target.hide(); cloneGallery.find('.col-50').each(function() { const imgSrc = $(this).find('img').attr('src') $(this).attr('data-dot', ``) $(this).find('.js-smartPhoto').removeAttr('data-group') }); cloneGallery.owlCarousel({ dots: true, nav: false, autoplay: 5000, items: 1, loop: true, dotsData: true }); $('.product-img-gallery .owl-item:not(.cloned) .js-smartPhoto').SmartPhoto({nav: false}); } else if ($(window).width() >= 1025 && breakPoint !== 'desktop') { breakPoint = 'desktop' target.show(); $('.product-img-gallery.owl-carousel').remove() } }); $(window).trigger('resize') })