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, 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; // ========================================================== // 依寬度判斷行為 // ========================================================== function productSlideMobile() { $('.productImg').owlCarousel({ loop : false, items : 1, nav : true, }); } function productSlideDesktop() { $('.productImg').owlCarousel({ loop : false, items : 1, nav : false, dots: false, }); } _window.on('resize',function(){ if(_window.width() <= 1023 && change_1023 != 1023){ change_1023 = 1023; }else if(_window.width() > 1023 && change_1023 != 1200){ change_1023 = 1200; } if( _window.width() > 769 && change != 960){ change = 960; $('.productView .moreview').removeAttr('style'); $.get('/products/ajax/detail/productView_pc.php',{sid:$(".wishlist").attr("sid")}, function(data,status){ $('.productView').html(data); // productSlideDesktop(); moreview = true; model.smallPicBox(); model.videoBox(); // model.zoomBox(); if($(window).width()>1025){ var pic_h = $('.productView').width(); var m_h = $('moreview').height(); var tihs_h = pic_h - m_h; $('.j-h').css('height',pic_h); // alert($('.j-h').attr('class')); } }); $('.item-1').off('click','img'); }else if(_window.width() <= 769 && change != 769){ change = 769; $.get('/products/ajax/detail/productView_moblie.php',{sid:$(".wishlist").attr("sid")}, function(data,status){ $('.productView').html(data); productSlideMobile(); $('.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("style")){ $("#big_picture").hide(); document.getElementById("Video").play(); }else{ $("#big_picture").show(); document.getElementById("Video").pause(); } } }); }); }; }); /* if($(window).width()>1025){ var pic_h = $('.productView').width(); var m_h = $('moreview').height(); var tihs_h = pic_h - m_h; $('.j-h').css('height',pic_h); alert($('.j-h').attr('class')); } */ //關閉跳窗 $(".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; }) // ========================================================== // 靜態頁跳窗 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'); $.ajax({ method: "GET", url, }).done(function(res) { const insertData = $(res + filter).html(); $('.popupBlock').html(insertData); $wrap.find('.popupWrapper').addClass('in-open'); $wrap.addClass('popupBox-active'); }).error(function(err) { console.log(err) }) }) $wrap.on('click', '.popupCloser', function(e) { popupClose(); }) $wrap.on('click', '.popupWrapper', function(e) { if(e.target === e.currentTarget) { popupClose(); } }) }) // ============================================================ // 手機版時商品主圖輪播左右滑限制不要觸發scroll B311910444 // ============================================================ $(function() { $(document).on("drag.owl.carousel", ".productImg.moblie", function(){ $("body").css("overflow", "hidden") }) $(document).on("dragged.owl.carousel", ".productImg.moblie", function(){ $("body").css("overflow", "") }) })