$(function() { /*後端*/ // $(".top_hot_keyword").click(function(){ // $.post('/ajax/ajax_hot_search-p.php', {ID: $(this).attr('did'), flag: 1 }, function(h){ // //alert(h); // }, 'html'); // }); $('.open-search').on('click', function() { // $('.search').addClass('show'); $('.search').show(); $('.search input').focus(); }); $('.search .close').on('click', function() { // $('.search').removeClass('show'); $('.search').hide(); }); $(".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); }); // //天邊=搜尋 // $('.open-search').on('mouseenter',function(){ // $('.search').addClass('show'); // $('.search input').focus(); // }); // $('.search .close').on('click',function(){ // $('.search').removeClass('show'); // }); $(".marquee").marquee(); $("#Select_This_Country").on("click", "li", 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'); }); //商品圖延遲載入 $('.productImg img').lazyload({ effect: 'fadeIn', failure_limit: 10, placeholder: '/images/common/loading.svg', }); var _window = $(window); var _body = $('body'); var change_1023 = 0; var nav_item = $('#menu-nav .nav-item'); var scroll_switch = true; // scroll_switch=nav_censor(scroll_switch); 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); }); //上方廣告 var button = 0; $('.top_adbox_button').on('click', function() { if (_window.width() <= 1023) { $(".top_adbox").remove(); if (button == 1) button--; } else { if (button == 0) { $(".top_adbox").css('height', 'auto'); $('.top_adbox .fa').removeClass('fa-plus').addClass('fa-times'); $('.top_adbox .inner').stop().animate({ 'max-height': 800 }, 1000, function() { button++; }); } else { $('.top_adbox .fa').removeClass('fa-times').addClass('fa-plus'); $('.top_adbox .inner').stop().animate({ 'max-height': 0 }, 1000, function() { button--; }); } } }); var change = 0; noisePop(); $(".heartList").owlCarousel({ nav: true, responsive: { 0: { items: 3 }, 768: { items: 4 }, 1024: { items: 6 } }, }); /* 手機平板 */ if (_window.width() <= 1024) { //上方廣告 if ($('.top_adbox').attr('tag-status') == '1') { $('.top_adbox .fa').removeClass('fa-plus').addClass('fa-times'); $(".top_adbox").show(); }; //天邊會員登入 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').on('click', '.wrapper', function() { if (language_click_n == 0) { language_click_n = 1; $('.language-box').addClass('open'); } else { language_click_n = 0; $('.language-box').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開合 if (/Windows/i.test(userAgent)) { $('#menu-nav').on('click', '.item-title', function() { var n = $(this).parent(".open").length; $('#menu-nav .nav-item').removeClass('open'); $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".nav-item").addClass('open'); } }).on(' click', '.subtitle', function() { var n = $(this).parent(".open-sub").length; $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".menu-item").addClass('open-sub'); } }); } else { $('#menu-nav').on('click', '.item-title', function() { var n = $(this).parent(".open").length; $('#menu-nav .nav-item').removeClass('open'); $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".nav-item").addClass('open'); } }).on(' click', '.subtitle', function() { var n = $(this).parent(".open-sub").length; $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".menu-item").addClass('open-sub'); } }); } } else { //上方廣告 if ($('.top_adbox').attr('tag-status') == '1') { $(".top_adbox").show(); $(".top_adbox_button").trigger('click'); }; } /* 手機 */ if (_window.width() <= 480 && change_1023 != 480) { change_1023 = 480; body_padding = 50; /* 平板 */ } else if (_window.width() > 480 && _window.width() <= 1023 && 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 }); } } }); } _window.on('scroll', function(event) { var scrollTop = _window.scrollTop(); if (scrollTop > 0) { $(".gotop").css("opacity", "1"); $(".gohome").css("opacity", "1"); $("body").addClass('is-sticky'); // _body.css('padding-top',body_padding_s+'px'); // scroll_switch=nav_censor(scroll_switch); } else { $(".gotop").css("opacity", "0"); $(".gohome").css("opacity", "0"); $("body").removeClass('is-sticky'); // _body.css('padding-top',body_padding+'px'); } }); var time_id; _window.on('resize', function() { clearTimeout(time_id); // time_id = setTimeout(nav_censor(scroll_switch),500); _window = $(window); // noisePop(); if (_window.width() <= 1023 && change_1023 == 1200) { //上方廣告 $('.top_adbox .fa').removeClass('fa-plus').addClass('fa-times'); $('.top_adbox_button').on('click', function() { $('.top_adbox').remove(); }); $('.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-007 .menu-item').off('hover'); //menu開合 // console.log(_window.width()); if (/Windows/i.test(userAgent)) { $('#menu-nav').on('click', '.item-title', function() { var n = $(this).parent(".open").length; $('#menu-nav .nav-item').removeClass('open'); $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".nav-item").addClass('open'); } }).on(' click', '.subtitle', function() { var n = $(this).parent(".open-sub").length; $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".menu-item").addClass('open-sub'); } }); } else { $('#menu-nav').on('click', '.item-title', function() { var n = $(this).parent(".open").length; $('#menu-nav .nav-item').removeClass('open'); $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".nav-item").addClass('open'); } }).on(' click', '.subtitle', function() { var n = $(this).parent(".open-sub").length; $('#menu-nav .menu-item').removeClass('open-sub'); if (n == 0) { $(this).parent(".menu-item").addClass('open-sub'); } }); } } 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() <= 1023 && 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-007').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-007 .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-007').on('mouseleave', function() { $('.menu-item.hover').removeClass('hover'); $('.menu-007 .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開合事件 $('#menu-nav').off('click', '.item-title').off('click', '.subtitle'); //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 }); } } }); } }); function nav_censor(scroll_switch) { if (scroll_switch) { for (var i = 1; i < nav_item.length; i++) { if (nav_item.eq(i).find('h3').height() > 45 || nav_item.eq(i).find('a.item-title').height() > 45) { nav_item.eq(i).addClass('nav-item-big'); scroll_switch = false; } } } return scroll_switch; } var nav_n = false; $('.menu-b').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-nav').on('click', '.footer-nav-item', function() { var n = $(this).index(); if (n < 2) { $('.footer-nav .footer-nav-item:lt(2)').addClass('open'); } else { $('.footer-nav .footer-nav-item:gt(1)').addClass('open'); } }); $('.footer-nav').on('click', '.open', function() { var n = $(this).index(); if (n < 2) { $('.footer-nav .footer-nav-item:lt(2)').removeClass('open'); } else { $('.footer-nav .footer-nav-item:gt(1)').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' }, success: function(d) { $("#Noise_Pop").remove(); } }); }); $(document).on("click", '.HITS_BT', 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 }, success: function(d) { if (url) { if (target == '_blank') { window.open(url); } else if ((typeof target === 'undefined') || (target == '')) { window.location = url; } else {} } } }); } else { alert("這是錯誤的連結"); } }); $(document).on("click", '.Collect_BT', function(e) { e.preventDefault(); if ($.isNumeric($(this).attr('Type')) && $.isNumeric($(this).attr('Collection_ID'))) { var Type = $(this).attr('Type'); var Collection_ID = $(this).attr('Collection_ID'); var _this = $(this); if (Type != 4) { $.ajax({ url: "/ajax/ajax_add_collection-p.php", type: "POST", cache: false, async: false, data: { "Type": Type, "Collection_ID": Collection_ID }, success: function(d) { if (d == "OK") { _this.addClass('click'); alert('收藏成功'); } else if (d == "Already") { alert("已收藏過!"); } else if (d == "ERROR") { alert('請先登入會員'); } } }); } else { $.ajax({ url: "/ajax/ajax_add_wish_list.php", type: "POST", cache: false, async: false, data: { "Type": 'Add', "SID": Collection_ID }, success: function(d) { if (d == "OK") { _this.addClass('click'); alert('收藏成功'); } else if (d == "NO_MEMBER") { alert('請先登入會員'); } } }); } } else { alert("這是錯誤的連結"); } }); $(document).on('click', '.Collect_Del_BT', function(e) { e.preventDefault(); var ID = $(this).data('id'); $.ajax({ url: "/ajax/ajax_del_collection-p.php", type: "POST", cache: false, async: false, data: { "ID": ID }, success: function(d) { if (d == "OK") { alert('取消收藏成功'); location.reload(); } } }) }) //點擊清空輸入框 $(".CLEAR_INPUT").one("click", function() { $(this).attr('placeholder', ''); }); $("#keywords").keyup(function() { $("body").append('
'); $("#keyword_search_div").css({ width: 205, position: "absolute", background: '#FFF', left: $(this).offset().left + 10, top: $(this).offset().top + 28, 'z-index': 9999 }); $.post('/include/ajax/ajax_index_search.php', { Keyword: $(this).val() }, function(h) { $("#keyword_search_div").html(h); $("#keyword_search_div").on("click", ".keyword_search_li", function() { $("#keywords").val($(this).text()); }); $(".keyword_search_li").on('mouseenter', function() { $(this).css({ "background-color": '#EEE' }); }); $(".keyword_search_li").on('mouseleave', function() { $(this).css({ "background-color": '#FFF' }); }); }, 'html'); }); }); 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); } } $(".otherEvent-wrapper .otherEvent-item").first().addClass('open'); $(".otherEvent-wrapper").on('mouseenter', '.otherEvent-item', function(event) { $(".otherEvent-item.open").removeClass('open'); $(this).addClass('open'); }); $('label.float-right').on('click', function() { $('body').toggleClass("fixed"); }); $('label.close').on('click', function() { $('body').toggleClass("fixed"); });