(function($){ const _window = $(window) let change_1023 = '' let change = '' /* 回到購買處 */ $('.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())); } /*評論預覽商品圖*/ $(".review-user").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}); }); $('.review-user').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'); // ========================================================== // 依寬度判斷行為 // ========================================================== function productSlideMobile() { $('.productImg').owlCarousel({ loop : false, items : 1, nav : true, }); } function productSlideDesktop() { $('.productImg').owlCarousel({ loop : false, items : 1, nav : false, dots: false, }); } smallPicBox(); _window.on('resize',function(){ if(_window.width() > 768 && change !== 'desktop'){ change = 'desktop' $('.productView .moreview').removeAttr('style'); $.get('/products/ajax/detail/productView_pc.php',{sid:$(".prod-param").attr("sid")}, function(data,status){ $('.productView').html(data).removeClass("theme-unset"); zoomBox(); moreview = false; videoBox(); verticalBx('.moreview') smallPicBox(); }); $('.item-1').off('click','img'); } else if(_window.width() <= 768 && change !== 'mobile') { change = 'mobile' $.get('/products/ajax/detail/productView_moblie.php',{sid:$(".prod-param").attr("sid")}, function(data,status){ $('.productView').html(data).removeClass("theme-unset"); mobileSlide(data) productSlideMobile(); }); }; }); //關閉跳窗 $(".inner").on('click','.close',function(){ $(".selectPopupBox").removeClass('is-show'); }); $('article').on('click','.open-preview',function(){ var nowitem = 0 if($(window).width() <= 768) { nowitem = $('.productImg .active').prevAll('.owl-item').length; } else { nowitem = $('.moreview .picitem.now').index() console.log(nowitem) } $('article .previewbox').css('display','block') $('article .previewbox').children().eq(nowitem).css('display','block'); //取得圖片寬度減去頁面寬度除以2進行位移 var picWidth = $('.previewbox .pic').width() var pageWidth = document.body.clientWidth $('.previewbox').scrollLeft((picWidth - pageWidth) / 2) $('body').addClass('overflow-hidden') }); $('article').on('click','.close',function(){ $('article .previewbox').removeAttr('style') .find('img').removeAttr('style'); $('body').removeClass('overflow-hidden') }); _window.trigger('resize'); scrollToTitleBottomMobile() $(document).on("specChangeSlider", function(){ verticalBx('.moreview') }) }(jQuery)); // ========================================================== // 查看更多活動 // ========================================================== ;(function($) { $('.product-active-wrapper').on('click', '.more-active', function(e) { $(this).parents('.product-active-wrapper').find('.active-list').toggleClass('in-active'); }) })($) // ========================================================== // moreview 直向slide // ========================================================== var bxSlide function verticalBx(selector) { //系列小圖套件 if(bxSlide){ bxSlide.destroySlider() } bxSlide = $(selector).bxSlider({ mode: 'vertical', minSlides: 4, slideWidth: 100, infiniteLoop: false, hideControlOnEnd: true, slideMargin: 7, speed: 100, pager: false, }); bxSlide.reloadSlider(); } // ========================================================== // mobile時將breadcrumb隱藏,滾動時顯示 // ========================================================== function scrollToTitleBottomMobile(){ if (!($(window).scrollTop()) && (document.body.clientWidth <= 480)){//mobile $("#breadcrumb").hide() } $(window).on("scroll",function(){ $("#breadcrumb").show() }) }