(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())); } $('.wordbox').on('click', '.slideTitle', function(event) { var box = $(this).parent('.word-close'); if(box.length == 0){ $(this).parent('.wordbox').addClass('word-close'); }else{ $(this).parent('.wordbox').removeClass('word-close'); } $(this).next('.slideBox').slideToggle(); }); /*評論預覽商品圖*/ $(".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, navText : ['',''], }); $('#preview').css('display','none'); $('.productView').owlCarousel({ loop : true, items : 1, nav : true, navText : ['',''], }); $(".recommend_l").owlCarousel({ navText:["",""], nav : true, responsive:{ 0:{ items : 2 }, 480:{ items : 3 }, 768:{ items : 4 }, 1024:{ items : 5 } }, }); var _window = $(window); _window.on('load',function(){ var change = 0; var change_1023 = 0; var moreview = false; var imgviewbox = $('.imgviewbox'); var pic_h = $('.productBox .pic').height(); var pic_w = $('.productBox .pic').width(); if(_window.width() > 769 && change != 960 ){ change = 960; moreview = true; // smallPicBox(); zoonbox(pic_h,pic_w) // videoBox(); }else if(_window.width() <= 768 && change!= 768){ change = 768; $('.productBox').on('click','.fa-search-plus',function(){ var pic_path = $(this).prev('.viewbox').attr('pic_path'); console.log(pic_path); var str='
'; $('body').append(str); }); $('body').on('click', '.picBigView .fa-times', function(event) { $('.picBigView').remove(); }); }; if(_window.width() <= 1023 && change_1023 != 1023){ change_1023 = 1023; }else if(_window.width() > 1023 && change_1023 != 1200){ change_1023 = 1200; } _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() > 768 && change != 960){ change = 960; zoonbox(pic_h,pic_w) $('.productBox').off('click','.fa-search-plus'); }else if(_window.width() <= 768 && change != 768){ change = 768; $('.productBox').off('mouseenter mousemove mouseleave','.pic'); $('.productBox').on('click','.fa-search-plus',function(){ var pic_path = $(this).prev('.viewbox').attr('pic_path'); console.log(pic_path); var str='
'; $('body').append(str); }); $('body').on('click', '.picBigView .fa-times', function(event) { $('.picBigView').remove(); }); }; }); }); /* 放大鏡效果 */ function zoonbox(pic_h,pic_w){ var mouse_in = false; $('.productBox').off('mouseenter mousemove mouseleave','.pic'); $('.productBox').on('mouseenter','.pic',function(){ $(this).find('.viewbox').css('opacity','1'); mouse_in = true; }).on('mousemove','.pic',function(e){ if(!mouse_in){ $(this).find('.viewbox').css('opacity','1'); mouse_in = true; } // $(this).find('.viewbox').css('opacity','1'); var move_h = (e.offsetY/pic_h)*-(900-pic_h); var move_w = (e.offsetX/pic_w)*-(900-pic_w); $(this).find('.viewbox').css({ 'background-position-y':move_h, 'background-position-x':move_w }); }).on('mouseleave','.pic',function(){ $(this).find('.viewbox').css('opacity','0'); mouse_in = false; }); } }(jQuery));