$(function(){ /*後端*/ $(".menu_class_a, .menu_sub_a").mouseover(function(){ var pic = $(this).attr('pic'); var url = $(this).attr('url'); var href = (url)? url: 'javascript:;'; var h = (pic)? '': ''; $(this).parents('.item-subitembox').find('.picbox').html(h); }); $(".menu_sub_a").mouseout(function(){ var pic = $(this).parents('.nav-item').find('.menu_class_a').attr('pic'); var url = $(this).parents('.nav-item').find('.menu_class_a').attr('url'); var href = (url)? url: 'javascript:;'; var h = (pic)? '': ''; $(this).parents('.nav-item').find('.item-subitembox').children('.picbox').html(h); }); if($(".top-marquee .item").length > 1){ $(".top-marquee").marquee({ duration:30000, allowCss3Support:true, pauseOnHover: true, duplicated:true }); }else if($(".top-marquee .item").length == 1){ $(".top-marquee").addClass("single-show") } //搜尋開啟 $(".icon-search").on("click", function(){ $(".search-wrapper").addClass("open") if($(window).width() < 769){ $("body").addClass("overflow-hidden") }else{ $(".search-wrapper .search-input").focus() } }) //搜尋關閉 $(".search-close").on("click", function(){ $(".search-wrapper").removeClass("open") $("body").removeClass("overflow-hidden") }) // $('.marquee').owlCarousel({ // loop : true, // // items : 5, // responsive:{ // 0:{ // items : 1 // }, // 1023:{ // items : 1 // } // }, // autoplay:true, // autoplayTimeout:3000, // nav :false, // navText : ['',''] // }); $(".Select_This_Country").on("click","li,label",function(){ $.post('/ajax/ajax_change_country.php', {ID: $(this).attr('sid')}, function(h){ if (typeof updatePage == "function"){ updatePage(); return false; } if(h){ //$("#This_Country_Pic").attr("src","/upload_files/fonlego-rwd/website/"+h); window.location.reload(); } }, 'html'); }); var _window = $(window); var _body = $('body'); var change_1023 = 0; var nav_item =$('#menu-nav .nav-item'); var scroll_switch=true; var body_padding = 121; var body_padding_s = 40; var userAgent = navigator.userAgent; /* 網頁loading */ // _window.on('load',function(){ // $(".loading").hide(); // }); /* 回頁首 */ $('.gotop').on('click',function(){ $("html,body").animate({scrollTop: 0},800); }); if($('.top_adbox').attr('tag-status') == '1'){ //今天沒看過 $(".top_adbox").addClass("open") }else if(($('.top_adbox').attr('tag-status') != '1')&&($(window).width() < 1025)){ $(".top_adbox").hide() $('.top_adbox_button').on('click', function(){ if($(".top_adbox").hasClass("open")){ $(".top_adbox").removeClass("open") $(".top_adbox").hide() } }) } $('.top_adbox_button').on('click', function(){ if($(".top_adbox").hasClass("open")){ $(".top_adbox").removeClass("open") }else{ $(".top_adbox").addClass("open") } }); var change = 0; noisePop(); /* 手機平板 */ if(_window.width() <= 1024){ //天邊會員登入 var member_click_n=0; $('.shopbox span.fa-user').on('click',function(){ if(member_click_n==0){ member_click_n=1; $('.userbox').addClass('open'); }else{ member_click_n=0; $('.userbox').removeClass('open'); } }); var language_click_n=0; $('.language_t').on('click','.wrapper ',function(){ if(language_click_n==0){ language_click_n=1; $('.language_t').addClass('open'); }else{ language_click_n=0; $('.language_t').removeClass('open'); } }); //天邊會員登入 var language_click_n=0; $('#language').on('click','.wrapper ',function(){ if(language_click_n==0){ language_click_n=1; $('#language').addClass('open'); }else{ language_click_n=0; $('#language').removeClass('open'); } }); //搜尋 var search_dom=$("#Top_Search"), search_n=0; search_dom.on('click', '.fa-search', function(event) { if(search_n==0){ search_n=1; search_dom.addClass('open'); }else{ search_n=0; search_dom.removeClass('open'); } }); //menu開合 $(".mobile-navitem-box").on("click", ".nav-item", function(){ let target = $(this).data("target") if(target && !$(this).hasClass("focus")){ $(".mobile-navitem-box .nav-item").removeClass("focus") $('#menu-nav .nav-item').removeClass('open'); $(this).addClass('focus') $('#menu-nav .nav-item[data-name="'+target+'"]').addClass('open') } }) /*$('#menu-nav .hover').removeClass('hover'); $('.mobile-navitem-box .focus').removeClass('focus'); $('.mobile-navitem-box').on('click','.m-item-title',function(){ var n = $(this).parent(".open").length; let target = $(this).parent(".nav-item").data("target") $('#menu-nav .nav-item').removeClass('open'); $('#menu-nav .menu-item').removeClass('open-sub'); $('.hall-content .wrapper').removeClass('open1'); $(this).parent(".nav-item").removeClass('focus') if(n == 0){ $(this).parent(".nav-item").addClass('focus') $('#menu-nav .nav-item[data-name="'+target+'"]').addClass('open') } })*/ } /* 手機 */ if(_window.width() <= 480 && change_1023 != 480){ change_1023 = 480; body_padding = 50; /* 平板 */ }else if(_window.width() > 480 && _window.width() <= 1024 && change_1023 != 1023){ change_1023 = 1023; body_padding = 75; body_padding_s = 50; nav_item.find('.subitem').attr('type','checkbox'); /* 電腦 */ }else if(_window.width() > 1023 && change_1023 != 1200){ change_1023 = 1200; body_padding = 121; body_padding_s = 40; $('.menu-002 .menu-item:nth-child(2)').addClass('hover'); $('.menu-002').on('mouseenter','.subtitle',function(){ // console.log($('menu-item .hover')); $('.menu-002').find('.hover').removeClass('hover'); $(this).parents('.menu-item').addClass('hover'); }).on('mouseleave',function(){ $('.menu-002').find('.hover').removeClass('hover'); $('.menu-002 .menu-item:nth-child(2)').addClass('hover'); }); //天邊會員登入hover下拉 $('.shopbox span.fa-user').on('mouseenter',function(){ $('.userbox').addClass('open'); }); //天邊購物車hover下拉 $('.shopbox #Shop_Cart_Total').on('mouseenter',function(){ $("#Header_Shopcart").load('/ajax/ajax_get_cart.php',''); $('.shopping-cartbox').addClass('open'); }); $('.shopbox').on('mouseleave',function(){ var _this_user=$(this).find('.userbox'), _this_shop=$(this).find('.shopping-cartbox'); if(_this_user.length==1){ $('.userbox').removeClass('open'); }else if(_this_shop.length==1){ $('.shopping-cartbox').removeClass('open'); } }); //hover menu-item change subitem height $('#menu-nav .nav-item').hover(function(){ var subitemboxheight = $(this).find('.menu-002 .hover .subitembox').outerHeight(); if($(this).has('hover')){ if(subitemboxheight>340){ $(this).find('.menu-002').css({'min-height':subitemboxheight+1}); } } },function(){ $('.menu-002').removeAttr('style'); }); $('#menu-nav .menu-002 .menu-item').hover(function(){ if($(this).hasClass('hover')){ var subitemboxheight = $(this).find('.subitembox').outerHeight(); if(subitemboxheight>340){ $(this).parents('.menu-002').css({'min-height':subitemboxheight+1}); } } }); } var scrollTemp = 0 //用來判斷上下捲動 _window.on('scroll', function(event) { let header = $(".header-01") let headerBottom = $(".headerBottom") var scrollTop = $(window).scrollTop() if(scrollTop>0 && ($(document).height() - $(window).height()) > header.height() ){ $("body").addClass('is-sticky'); // _body.css('padding-top',body_padding_s+'px'); }else{ $(".gotop").css("opacity","0"); $("body").removeClass('is-sticky'); // _body.css('padding-top',body_padding+'px'); } if(scrollTop > scrollTemp && scrollTop > header.height() && !$(".navBox").hasClass("open-nav") && !$("body").hasClass("overflow-hidden")){ //向下滑隱藏整個header(桌機板和首頁行動板) //if(!(($(".not-index").length > 0) && (_window.width() < 1025))){ header.css({ "transform": "translateY(-"+header.height()+"px)" }) headerBottom.css({ "transform": "translateY("+headerBottom.outerHeight()+"px)" }) //} $("body").addClass("header-hide") $(".gotop").css("opacity","0"); scrollTemp = scrollTop }else if(scrollTop < scrollTemp){ header.css({ "transform": ""//取消樣式 }) headerBottom.css({ "transform": ""//取消樣式 }) $("body").removeClass("header-hide") if(scrollTop != 0){ $(".gotop").css("opacity","1"); }else{ $(".gotop").css("opacity","0"); } scrollTemp = scrollTop } }); var time_id; _window.on('resize',function(){ clearTimeout(time_id); _window = $(window); // noisePop(); if(_window.width() <= 1024 && change_1023 ==1200){ $('.search').removeAttr('style'); $('.shopbox span.fa-user,.shopbox .fa-shopping-cart').off('mouseenter'); //天邊會員登入 var member_click_n=0; $('.shopbox span.fa-user').on('click',function(){ if(member_click_n==0){ member_click_n=1; $('.userbox').addClass('open'); }else{ member_click_n=0; $('.userbox,.shopping-cartbox').removeClass('open'); } }); $('.shopbox').off('mouseleave'); //off submenu-item 自動調整高度 $('#menu-nav .nav-item').off('hover'); $('#menu-nav .menu-002 .menu-item').off('hover'); $('#menu-nav .menu-item .hover').removeClass('hover'); $('#mobile-navitem-box .focus').removeClass('focus'); //menu開合 $(".mobile-navitem-box").on("click", ".nav-item", function(){ let target = $(this).data("target") if(target && !$(this).hasClass("focus")){ $(".mobile-navitem-box .nav-item").removeClass("focus") $('#menu-nav .nav-item').removeClass('open'); $(this).addClass('focus') $('#menu-nav .nav-item[data-name="'+target+'"]').addClass('open') } }) } if(_window.width() <= 480 && change_1023 != 480){ change_1023 = 480; body_padding = 50; var scrollTop = _window.scrollTop(); // if(scrollTop>0){ // _body.css('padding-top',body_padding_s+'px'); // }else{ // _body.css('padding-top',body_padding+'px'); // } }else if(_window.width() > 480 && _window.width() <= 1024 && change_1023 != 1023){ change_1023 = 1023; body_padding = 75; body_padding_s = 50; var scrollTop = _window.scrollTop(); nav_item.find('.subitem').attr('type','checkbox'); // if(scrollTop>0){ // _body.css('padding-top',body_padding_s+'px'); // }else{ // _body.css('padding-top',body_padding+'px'); // } $('.menu-item .subtitle').off('mouseenter'); $('.menu-002').off('mouseleave'); }else if(_window.width() > 1023 && change_1023 != 1200){ change_1023 = 1200; body_padding = 121; body_padding_s = 40; var scrollTop = _window.scrollTop(); nav_item.find('.subitem').attr('type','radio'); // if(scrollTop>0){ // _body.css('padding-top',body_padding_s+'px'); // }else{ // _body.css('padding-top',body_padding+'px'); // } $('.menu-002 .menu-item:nth-child(2)').addClass('hover'); $('.menu-item .subtitle').on('mouseenter',function(){ //console.log($('menu-item .hover')); $('.menu-item.hover').removeClass('hover'); $(this).parents('.menu-item').addClass('hover'); }); $('.menu-002').on('mouseleave',function(){ $('.menu-item.hover').removeClass('hover'); $('.menu-002 .menu-item:nth-child(2)').addClass('hover'); }); $('.shopbox span.fa-user').off('click'); //天邊會員登入 $('.shopbox span.fa-user').on('mouseenter',function(){ $('.userbox').addClass('open'); }); //天邊購物車hover下拉 $('.shopbox .fa-shopping-cart').on('mouseenter',function(){ $("#Header_Shopcart").load('/ajax/ajax_get_cart.php',''); $('.shopping-cartbox').addClass('open'); }); $('.shopbox').on('mouseleave',function(){ $('.userbox,.shopping-cartbox').removeClass('open'); }); //移除menu開合事件 $('.mobile-navitem-box').off('click','.nav-item') //hover menu-item subitem 自動調整高度 $('#menu-nav .nav-item').hover(function(){ var subitemboxheight = $(this).find('.menu-002 .hover .subitembox').outerHeight(); if($(this).has('hover')){ if(subitemboxheight>340){ $(this).find('.menu-002').css({'min-height':subitemboxheight+1}); } } },function(){ $('.menu-002').removeAttr('style'); }); $('#menu-nav .menu-002 .menu-item').hover(function(){ if($(this).hasClass('hover')){ var subitemboxheight = $(this).find('.subitembox').outerHeight(); if(subitemboxheight>340){ $(this).parents('.menu-002').css({'min-height':subitemboxheight+1}); } } }); } }); var nav_n = false; $('.menu-b, .liff-menu-btn').on('click',function(){ if(!nav_n){ nav_n = true; $(this).addClass('close'); $('.nav-bg,.navBox').addClass('open-nav'); $('body').addClass('overflow-hidden'); }else{ nav_n = false; $(this).removeClass('close'); $('.nav-bg,.navBox').removeClass('open-nav'); $('body').removeClass('overflow-hidden'); } }); $('.nav-bg').on('click',function(){ nav_n = false; $('.menu-b').removeClass('close'); $('.nav-bg,.navBox').removeClass('open-nav'); $('body').removeClass('overflow-hidden'); }); $('.footer_menu').on('click','.menu-item',function(){ $(this).addClass('open'); }); $('.footer_menu').on('click','.open',function(){ $(this).removeClass('open'); }); $("#Noise_Pop").on("click",".fa-times",function(e){ e.preventDefault(); $.ajax({ url:"/ajax/ajax_get_noisePop.php", type:"POST", cache:false, async:false, data:{Type:'Cancel'}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ $("#Noise_Pop").remove(); } }); }); //點擊率 $(".HITS_BT").on("click",function(e){ e.preventDefault(); if( $.isNumeric($(this).attr('hid')) && $.isNumeric($(this).attr('hdid')) ){ var hid = $(this).attr('hid'); var hdid = $(this).attr('hdid'); var url = $(this).attr('href'); var target = $(this).attr('target'); $.ajax({ url:"/ajax/ajax_add_ad_hits-p.php", type:"POST", cache:false, async:false, data:{Hid: hid , Hdid : hdid}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(url){ if(target == '_blank'){ window.open(url); }else if( ( typeof target === 'undefined' ) || (target == '') ){ window.location = url; }else{ } } } }); }else{ alert(_jsLang.這是錯誤的連結); } }); //讚數加減 $(".Thumbs_BT").on("click",function(e){ e.preventDefault(); if( $.isNumeric($(this).attr('pdid')) ){ var h = $(this); var ID = h.attr('pdid'); var Type = (h.attr('tbup')==1)?'Sub':'Add'; $.ajax({ url:"/ajax/ajax_add_thumbs-p.php", type:"POST", cache:false, async:false, dataType:"json", data:{Type: Type , ID : ID}, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ if(d.Thumbs_Up=='1'){ $('.content').find('.Thumbs'+ID).attr('tbup','1'); $('.content').find('.Thumbs'+ID).find('.Thumbs_icon').removeClass('fa-thumbs-o-up'); $('.content').find('.Thumbs'+ID).find('.Thumbs_icon').addClass('fa-thumbs-up'); }else{ $('.content').find('.Thumbs'+ID).attr('tbup','0'); $('.content').find('.Thumbs'+ID).find('.Thumbs_icon').removeClass('fa-thumbs-up'); $('.content').find('.Thumbs'+ID).find('.Thumbs_icon').addClass('fa-thumbs-o-up'); } $('.content').find('.Thumbs'+ID).find('.Thumbs_Num').html(d.Thumbs_Num); } }); }else{ alert(_jsLang.這是錯誤的連結); } }); //點擊清空輸入框 $(".CLEAR_INPUT").one("click", function(){ $(this).attr('placeholder',''); }); //語系選擇 $(".Select_This_Lang").on("click","li,label",function(){ $.post('/ajax/ajax_change_language.php', {Name: $(this).attr('sid')}, function(h){ window.location.reload(); /*if (typeof updatePage == "function"){ updatePage(); return false; } if(h){ window.location.reload(); }*/ }, 'html'); }); // $("#keywords").autocomplete({ // source: function( request, response ) { // $.ajax({ // url: "/ajax/ajax_get_keyword.php", // dataType: "json", // type:"POST", // data: { // search: request.term // }, // error:function(d){ // alert('網路連線過慢,網頁請重新整理'); // }, // success: function( data ) { // response( data ); // } // }); // } // }); //貨到通知改為連至門市 $(document).on('click','.informForPorter',function(){ window.location.href = '/'+$("#Website_Mall_ID").val()+'/store/'; }); //購物彈窗 $(document).on('click','.quickshop-popupbtn',function(){ var sid = $(this).attr('SID'), wrapper = $(this).parent(".warpper") var flag=1; $.ajax({ url:"/products/ajax/list/ajax_get_prod_quick.php", type:"POST", data:{type:1,SID:sid,prodlimit:wrapper.data("limit"),prodtype:wrapper.data("type")}, dataType: 'json', async: false, error:function(d){ alert('網路連線過慢,網頁請重新整理'); }, success:function(d){ let quickWrapper = $('.quickshop-wrapper') quickWrapper.html(d.data); quickWrapper.addClass("open") quickWrapper.data("limit",wrapper.data("limit")) quickWrapper.data("type",wrapper.data("type")) $("body").addClass("overflow-hidden") smallPicBox(quickWrapper) videoBox() window.dispatchEvent(new Event('resize')) //修復跳窗後moreview 寬度異常 } }) }); //關閉快速購物彈窗 $(document).on("click", ".quickshop-close", function(e){ $(this).parents(".quickshop-wrapper").removeClass("open") $("body").removeClass("overflow-hidden") }) $(".quickshop-wrapper").on("click", function(e){ if($(e.target).hasClass("quickshop-wrapper")){ $(this).removeClass("open") $("body").removeClass("overflow-hidden") } }) //============================================================ // 規格展開 //============================================================ $(document).on("click", ".selectPopupBox-viewmore", function(){ let parent = $(this).parent(".multi-spec") if(parent.hasClass("open")){ parent.removeClass("open") $(this).find(".viewmore-text").text("看更多規格") }else{ parent.addClass("open") $(this).find(".viewmore-text").text("收合規格") } }) //=========================================================== // 篩選器折疊/展開 //=========================================================== $(document).on("click", ".leftaside-collapse-btn",function(){ let wrapper = $(this).parents(".leftaside-collapse-wrapper") if(wrapper.hasClass("collapse")){ wrapper.removeClass("collapse") }else{ wrapper.addClass("collapse") } }) //=========================================================== // 桌機橫式scrollbar拖動 start //=========================================================== function updateScrollPosition(e, containerJqueryObj, position){ containerJqueryObj.scrollLeft(position.left + position.x - e.clientX) } $(".row-scrollbar").each(function(){ let _target = $(this) let _grabed = false let _position = {left: 0, x: 0} let specialChild = _target.find("img, a") let clickFlag = false let bindMousemove = function(e){ if(_grabed){ updateScrollPosition(e, _target, _position) } } let bindMouseup = function(e){ _grabed = false _target.css({ "cursor": "grab", "user-select": "initial" }) $(document).off("mouseup", bindMouseup) $(document).off("mousemove", bindMousemove) } specialChild.prop("draggable", false).on("dragstart", function(){ return false; }) _target.on({ "mousedown": function(e){ _target.css({ "cursor": "grabbing", "user-select": "none" }) _grabed = true _position = { left: _target.scrollLeft(), x: e.clientX } $(document).on("mouseup", bindMouseup) $(document).on("mousemove", bindMousemove) clickFlag = true setTimeout(function(){ //短觸視為click clickFlag = false },100) }, "click": function(e){ if(!clickFlag){ e.preventDefault() } } }) }) //=========================================================== // 桌機橫式scrollbar拖動 end //=========================================================== }); function smallPicBox(wrapper){ /* 小圖hover效果及切換功能 */ let moreview = wrapper.find(".moreview"), zoonbox = wrapper.find(".zoonbox"), owlitem = wrapper.find(".owl-item"), picitem = wrapper.find(".picitem") if(moreview.find(".picitem").length > 0){ moreview.owlCarousel({ loop:false, items : 4, margin: 12, nav : true, dots:false }).on('mouseleave','.owl-stage-outer', function() { zoonbox.removeAttr('style'); }) .on('click','.owl-item', function() { var now = $(this).index(); owlitem.not(this).find('.picitem').removeClass('now'); $(this).find('.picitem').addClass('now'); zoonbox.removeClass('now').eq(now).addClass('now'); }) .on('mouseenter','.owl-item', function() { var now = $(this).index(); //var nowbox = $('.productImg .now').index(); //console.log(nowbox ); zoonbox.css('display','none').eq(now).css('display','block'); //$('.productImg .now').css('display','none'); }) .on('mouseleave','.owl-item', function() { var now = $(this).index(); zoonbox.eq(now).css('display','none'); }); }else{ moreview .on('mouseleave', function() { zoonbox.removeAttr('style'); }) .on('click','.picitem', function() { var now = $(this).index(); picitem.removeClass('now'); $(this).addClass('now'); zoonbox.removeClass('now').eq(now).addClass('now'); }) .on('mouseenter','.picitem', function() { var now = $(this).index(); //var nowbox = $('.productImg .now').index(); //console.log(nowbox ); zoonbox.css('display','none').eq(now).css('display','block'); //$('.productImg .now').css('display','none'); }) .on('mouseleave','.picitem', function() { var now = $(this).index(); 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, 300, 150); }; } } function errorbox(title,content,button){ var html=''; $('body').append(html); $('body').on('click', '#popupBox .close', function(event) { $('#popupBox').remove(); }); }; function noisePop(){ if($(window).width()>= 961){ nosise_animate = true; var n = 30;//最大值 var r = Math.floor(Math.random()*n)+1; setTimeout(function(){ $.ajax({ url:"/ajax/ajax_get_noisePop.php", type:"POST", cache:false, async:false, data:{Type:'GET'}, success:function(d){ if(d){ $("#Noise_Pop").prepend(d); setTimeout(function(){ $("#Noise_Pop .noise_box:last").remove(); },5000); setTimeout(function(){ noisePop(); },r*1100); } } }); },r*1000); } } var _masonry_set = { columnWidth: 15, itemSelector: '.menu-item', gutter: 20, transitionDuration: 0 }; $('.nav-item').find('.item-subitembox .menu1-left').each(function() { if ($(this).find('.menu-item').length <= 2) { $(this).addClass('no-after'); } }) $(window).resize(function() { if ($(window).width() <= 1024) { $('.nav-item').off('mouseenter'); $('.nav-item').find('.item-subitembox').each(function() { $(this).removeAttr('style'); }) } else { } }) if ($(window).width() <= 1024) { $('.nav-item').find('.item-subitembox').each(function() { $(this).removeAttr('style'); }) } else { } $('main').on('click', '.club-aside', function(event) { $('body').css('position','fixed'); }); $('main').on('click', '.close-m', function(event) { $('body').removeAttr('style'); });