(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 } }, }); var _window = $(window); var change = 0; var change_1023 = 0; var moreview = false; if(_window.width() > 769 && change != 960 ){ change = 960; moreview = true; smallPicBox(); videoBox(); }else if(_window.width() <= 768 && change!= 768){ change = 768; $.get('/tw/products/ajax/detail/productView_moblie.php',{sid:$(".wishlist").attr("sid")}, function(data,status){ //fbq('track','AddToCart'); $('.productView').html(data) $('.productImg').owlCarousel({ loop : false, items : 1, nav : true, }); $('.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() <= 1023 && change_1023 != 1023){ change_1023 = 1023; }else if(_window.width() > 1023 && change_1023 != 1200){ change_1023 = 1200; } //關閉跳窗 $(".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.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; $('.productView .moreview').removeAttr('style'); $.get('/tw/products/ajax/detail/productView_pc.php',{sid:$(".wishlist").attr("sid")}, function(data,status){ //fbq('track','AddToCart'); //console.log("pc板"); //console.log(data+"+"+status); $('.productView').html(data); moreview = true; smallPicBox(); videoBox(); }); $('.item-1').off('click','img'); }else if(_window.width() <= 768 && change != 768){ change = 768; $.get('/tw/products/ajax/detail/productView_moblie.php',{sid:$(".wishlist").attr("sid")}, function(data,status){ //fbq('track','AddToCart'); //console.log("手機板"); //console.log(data+"+"+status); $('.productView').html(data) $('.productImg').owlCarousel({ loop : false, items : 1, nav : true, }); $('.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(); } } }); }); }; }); // ========================================================== // 折價券 // ========================================================== $('.product-coupon .coupon-list').owlCarousel({ loop : true, margin: 25, navText : ['',''], responsive:{ 0:{ items : 1, nav : false, dots: true, }, 769:{ items : 2, nav : false, dots: true, }, 1201:{ items : 3, nav : true, dots: false, } }, }); }(jQuery)); function smallPicBox(){ /* 小圖hover效果及切換功能 */ if($(".moreview .picitem ").length > 5){ $(".productView .moreview").owlCarousel({ loop:false, items : 5, nav : true, }).on('mouseleave','.owl-stage-outer', function() { $(".productView .zoonbox").removeAttr('style'); }) .on('click','.owl-item', function() { var now = $(this).index(); $(".productView .owl-item").not(this).find('.picitem').removeClass('now'); $(this).find('.picitem').addClass('now'); $(".productView .zoonbox").removeClass('now').eq(now).addClass('now'); }) .on('mouseenter','.owl-item', function() { var now = $(this).index(); //var nowbox = $('.productImg .now').index(); //console.log(nowbox ); $(".productView .zoonbox").css('display','none').eq(now).css('display','block'); //$('.productImg .now').css('display','none'); }) .on('mouseleave','.owl-item', function() { var now = $(this).index(); $(".productView .zoonbox").eq(now).css('display','none'); }); }else{ $(".productView .moreview") .on('mouseleave', function() { $(".productView .zoonbox").removeAttr('style'); }) .on('click','.picitem', function() { var now = $(this).index(); $(".productView .picitem").removeClass('now'); $(this).addClass('now'); $(".productView .zoonbox").removeClass('now').eq(now).addClass('now'); }) .on('mouseenter','.picitem', function() { var now = $(this).index(); //var nowbox = $('.productImg .now').index(); //console.log(nowbox ); $(".productView .zoonbox").css('display','none').eq(now).css('display','block'); //$('.productImg .now').css('display','none'); }) .on('mouseleave','.picitem', function() { var now = $(this).index(); $(".productView .zoonbox").eq(now).css('display','none'); }); } } /*影片效果*/ function videoBox(){ //影片控制 $(".moreview").on('click','.video_control',function(){ var video = document.getElementById("Video"); if(video.paused){ $(this).addClass('fa-pause').removeClass('fa-play'); video.play(); }else{ $(this).addClass('fa-play').removeClass('fa-pause'); video.pause(); } }); //影片預覽圖 if(document.getElementById("Video")){ document.getElementById("Video").oncanplay=function(){ var video = $("#Video").get(0); var canvas = document.getElementById("video_review"); canvas.getContext('2d').drawImage(video, 0, 0, 66, 92); }; } }