/* Safari 『強制』禁止縮放 ==================================================*/ document.documentElement.addEventListener('touchstart', function (e) { if (e.touches.length > 1) e.preventDefault(); }, false); var lastTouchEnd = 0; document.documentElement.addEventListener('touchend', function (e) { var now = (new Date()).getTime(); if (now - lastTouchEnd <= 300) e.preventDefault(); lastTouchEnd = now; }, false); var script = function () { var $body = $('html,body'); var winH = $(window).height(); var winW = $(window).width(); var $win = $(window); var scrollBottom = $(window).scrollTop() + $(window).height(); var conH = $('.container').height(); var headerH = $('header').height(); $('#myfooter .backtotop').click(function () { $body.animate({ scrollTop: 0 }, 600); }) /* 選單 ------------------------------------------------------------*/ function navde() { $('.burger').attr('toggle', '0'); $('.burger').removeClass('isclick'); TweenMax.to('.navbox', .4, { autoAlpha: 0, zIndex: -1 }); $('.mainnav').css('height',''); if(winW <= 1024){ $('.mainnav').hide(); }else{ $('.mainnav').show(); } if (winW >= 1024) { $('.nav').show(); $('#myheader').find('.container').css({ 'background': '#fff' }) $('body,html').css({ 'overflow': '', 'height': '' }) } else { $('.nav').slideUp(); // $('#myheader').find('.container').css({ // 'background': '#000' // }) } } navde(); $('.burger').click(function () { var menuOpen = $('.burger').attr('toggle'); if (menuOpen == 0) { $('.nav').slideDown(); $('.mainnav').slideDown(); $('.burger').attr('toggle', '1'); $('.burger').addClass('isclick'); $('body,html').css({ 'overflow': 'hidden', 'height': '100vh' }) // if (winW <= 1024) { // TweenMax.to($('#myheader').find('.container'), .1, { // backgroundColor: '#262626', // ease: Linear.easeNone // }); // } } else if (menuOpen == 1) { $('.nav').slideUp(); $('.mainnav').css('height',''); $('.mainnav').slideUp(); $('.burger').attr('toggle', '0'); $('.burger').removeClass('isclick'); $('body,html').css({ 'overflow': '', 'height': '' }) // if (winW <= 1024) { // TweenMax.to($('#myheader').find('.container'), 1, { // backgroundColor: '#000', // ease: Linear.easeNone // }); // } } }); // 內頁選單select var thispage = $('body').data('p'); //var thisrule = $('.wrapper').data('rule'); function navselect(){ $('#myheader').find('.nav').find('li[data-p="' + thispage + '"]').addClass('select'); } navselect() //選單改變顏色 if ($('.rule-how').length) { $('._Note20ultra .capacities label').on('click', function () { $('._Note20ultra #note20ultracolor2').prop("checked", true); }) $('._Note20 .capacities label').on('click', function () { $('._Note20 #note20color3').prop("checked", true); }) $('._Galaxys22 .capacities label').on('click', function () { $('._Galaxys22 #galaxys22color3').prop("checked", true); }) } /* QA ------------------------------------------------------------*/ $('.qna').find('.box').each(function () { $(this).click(function () { $(this).toggleClass('isopen'); if ($(this).hasClass('isopen')) { $(this).find('.txt').slideDown(); } else { $(this).find('.txt').slideUp(); } }) }) /* 活動辦法切換 -----------------------------------------------------*/ $('.storebuy .maintab .bt').eq(0).addClass('select'); $('.storebuy .inner').eq(0).show(); $('.storebuy .maintab .bt').click(function () { var _ind = $(this).data('tab'); $('.storebuy .maintab .bt').removeClass('select'); $('.storebuy .maintab .bt[data-tab="' + _ind + '"]').addClass('select'); $('.storebuy .inner').fadeOut('fast'); $('.storebuy .inner[data-inner="' + _ind + '"]').fadeIn('fast',function () { var pos = []; $(this).find('.listing').find('.one').each(function (i, obj) { var t = $(obj).offset().top; pos.push(t); }) // console.log(pos); $(this).find('.subtab').find('li').click(function () { var cur = $(this).index(); TweenMax.to('body,html', .8, { scrollTop: pos[cur] , ease: Quart.easeOut }); }) }); }) function promoSubscroll() { $('.storebuy .inner').each(function () { var pos = []; $(this).find('.listing').find('.one').each(function (i, obj) { var t = $(obj).offset().top; pos.push(t); }) // console.log(pos); $(this).find('.subtab').find('li').click(function () { var cur = $(this).index(); TweenMax.to('body,html', .8, { scrollTop: pos[cur] , ease: Quart.easeOut }); }) }) } promoSubscroll(); var hash = location.hash; if ($('#promo').length) { var promoPos = $('#promo').offset().top; } function promoscroll() { if (hash == '#promo' || hash == '#promoStore' || hash == '#promoOnline') { TweenMax.to('body,html', .8, { scrollTop: promoPos, ease: Quart.easeOut }); } } promoscroll(); if( $('#promo').length ){ if( hash == '#promoStore' ){ $('.storebuy .maintab .bt').removeClass('select'); $('.storebuy .inner').fadeOut('fast'); $('.storebuy .maintab .bt[data-tab="2"]').addClass('select'); $('.storebuy .inner[data-inner="2"]').fadeIn('fast'); }else if( hash == '#promoOnline' ){ $('.storebuy .maintab .bt').removeClass('select'); $('.storebuy .inner').fadeOut('fast'); $('.storebuy .maintab .bt[data-tab="3"]').addClass('select'); $('.storebuy .inner[data-inner="3"]').fadeIn('fast'); } } /* 取消原因 ------------------------------------------------------------*/ $('.lb-reason .selectbox select').click(function () { $('.lb-reason .main').addClass('open'); }); /* 熱銷通路切換 -----------------------------------------------------*/ var thisPath = 1, prevPath = '', $btn_tab = $('.soldout .tabbox .tab'); var pathPagechange = function () { if (thisPath !== prevPath) $('.soldout .btnlist').css({ 'opacity': 0, 'z-index': -1, 'height': 0 }) $('.soldout .btnlist[data-list="' + thisPath + '"]').css({ // 'opacity':1, 'height': 'auto', 'z-index': 1 }) var pathAni = new TimelineMax(); pathAni.to($('.soldout .btnlist[data-list ="' + thisPath + '"]'), .3, { css: { opacity: 1, height: 'auto' }, ease: Linear.easeNone }); $btn_tab.removeClass('select'); $btn_tab.eq(thisPath - 1).addClass('select'); prevPath = thisPath; } pathPagechange(thisPath); $btn_tab.click(function () { var $this = $(this); if ($this.hasClass('js-justLink')) return; thisPath = $this.index(); pathPagechange(); }); // tab切換效果 $btn_tab.click(function () { var _ind = $(this).index() - 1, _w = $(this).outerWidth(true); if (_ind === 2) return; TweenMax.to($(this).parent().find('.ovr'), .3, { left: _ind * _w, ease: Quart.easeInOut }); }) /* promo ------------------------------------------------------------*/ // 主選切換 var thisS4 = 0, prevS4 = '', $btn_sec4 = $('.promobox .tabbox .tab'); var sec4Pagechange = function () { if (thisS4 !== prevS4) $('.promobox .inner').fadeOut(0); $('.promobox .inner[data-inner ="' + thisS4 + '"]').fadeIn(500); $btn_sec4.removeClass('select'); $btn_sec4.eq(thisS4).addClass('select'); prevS4 = thisS4; } sec4Pagechange(thisS4); $btn_sec4.click(function () { thisS4 = $(this).index(); sec4Pagechange(); }); //副選單 $('.promobox .inner').each(function () { $(this).find('.submenu').find('li').each(function () { $(this).click(function () { var _ind = $(this).index(); var _thispos = $(this).closest('.inner').find('.listing').find('.one').eq(_ind).offset().top; $body.animate({ scrollTop: _thispos }, 600); }) }) }) // var hash = location.hash; // function promoscroll() { // if (hash != '' && hash == '#promo') { // TweenMax.to('body,html', .8, { // scrollTop: promoPos, // ease: Quart.easeOut // }); // } // if (hash != '' && hash == '#promo_1') { // TweenMax.to('body,html', .8, { // scrollTop: promoPos, // ease: Quart.easeOut // }); // thisS4 = 0; // sec4Pagechange(thisS4); // } // if (hash != '' && hash == '#promo_2') { // TweenMax.to('body,html', .8, { // scrollTop: promoPos, // ease: Quart.easeOut // }); // thisS4 = 1; // sec4Pagechange(thisS4); // } // if (hash != '' && hash == '#promo_3') { // TweenMax.to('body,html', .8, { // scrollTop: promoPos, // ease: Quart.easeOut // }); // thisS4 = 2; // sec4Pagechange(thisS4); // } // } // promoscroll(); /* Step1 選擇產品規格 -----------------------------------------------------*/ $('.step1').find('.choose').each(function () { $(this).find('dt,dd').click(function () { var productimg = $(this).data('img'); var phoneId = $(this).data('pdname'); var phoneCapa; $('.kv_product').addClass('hidekv'); }) }) /* ses_rule 活動辦法 -----------------------------------------------------*/ /* click */ $('.secrule.ses').find('.stepbox').each(function(){ $(this).find('.btnopen').click(function(){ $(this).toggleClass('isclick'); if( $(this).hasClass('isclick') ){ $(this).closest('.stepbox').find('.inner').slideDown(); }else{ $(this).closest('.stepbox').find('.inner').slideUp(); } }) }) /* page scroll */ if ($('.secrule').length) { var hash = location.hash, href; var thispage = 0; var pagescroll = true; var pageT = [], $sec = $('.anchorT'), $main = $('.wrapper'), // _mainTOP = $main.offset().top, ah = $main.outerHeight(true), pageName = ['galaxy-z6', 'galaxy-watch', 'galaxy-buds3', 'step', 'preorder-gift', 'early-pickup', 'freetrial', 'gathering', 'livestream', 'launch', 'trade-in', 'ew', 'installment', 'mobile-payment', 'bank', 'swallet', 'gstore', 'wasp', 'smembers', 'scare', 'eup'] var _thispagescroll = pageName.indexOf(hash); var pageReset = function () { pageT = []; winW = $win.width(); ah = $main.outerHeight(true); $sec.each( function (i, obj) { var t = $(obj).offset().top; pageT.push(t); if (i == $sec.length - 1) { pageT.push(ah); } } ); } var scrollPage = function (wt, whelf) { winH = $win.height(); winW = $win.width(); wt = $win.scrollTop(); whelf = winH / 3; for (var p = 0; p < $sec.length; p++) { if (wt > pageT[p] - whelf && wt < pageT[p + 1] - whelf) { thispage = p; } } href = pageName[thispage]; window.location.hash = href; } var scrollthispage = function () { var _pos; _thispagescroll = pageName.indexOf(hash.substr(1)); pageReset(); if (_thispagescroll != -1) { thispage = pageName.indexOf(hash.substr(1)); pageReset(); TweenMax.to('body,html', .1, { scrollTop: pageT[thispage], ease: Quart.easeOut }); href = pageName[thispage]; window.location.hash = href; pagescroll = false; } } scrollthispage(); $win.scroll(scrollPage); } /* lightbox ------------------------------------------------------------*/ var $lb = $('.lb'), $lbbox = $('.lbbox'); var lb_data, lb_data2, lbname, lbname2; TweenMax.set($('.lb'), { opacity: 0, zIndex: -1 }); var lbOpen = function (lb_data) { var lbAni = new TimelineMax(); lbAni.to($('.lb[data-lb="' + lb_data + '"]'), .3, { css: { zIndex: 9999 } }, '-=.3') .to($('.lb[data-lb="' + lb_data + '"]'), .3, { opacity: 1, ease: Linear.easeNone }); if ($('.restart').length) { $('.restart').click(lbClose); } $body.css({ 'overflow': 'hidden', 'position': '' }) } var lbOpen2 = function (lb_data) { var lbAni = new TimelineMax(); lbAni.to($('.lb2[data-lb2="' + lb_data + '"]'), .3, { css: { zIndex: 9999 } }, '-=.3') .to($('.lb2[data-lb2="' + lb_data + '"]'), .3, { opacity: 1, ease: Linear.easeNone }); if ($('.restart').length) { $('.restart').click(lbClose); } $body.css({ 'overflow': 'hidden', 'position': 'fixed' }) } var lbClose = function (lb_data2) { var lbCloseAni = new TimelineMax(); lbCloseAni.to($('.lb'), .3, { opacity: 0, ease: Linear.easeNone }) .to($('.lb'), .3, { css: { zIndex: -1 } }); $body.css({ 'overflow': '', 'position': '' }) } var lbClose2 = function (lb_data2) { var lbCloseAni = new TimelineMax(); lbCloseAni.to($('.lb2'), .3, { opacity: 0, ease: Linear.easeNone }) .to($('.lb2'), .3, { css: { zIndex: -1 } }); $body.css({ 'overflow': '', 'position': '' }) } // lbOpen('complete'); $('.libtn').click(function () { var lbname = $(this).data('lb'); lbOpen(lbname); return false; }); $('.libtn2').click(function () { var lbname = $(this).data('lb2'); lbOpen2(lbname); return false; }); $('.lb .btn_x,.lb .btnClose').click(function () { lbClose(); }); $('.lb .btn_ok').click(function () { lbClose(); }); // 配件刪除 $('.lb-detail').find('.listline').each(function(){ $(this).find('.del').click(function(){ $(this).closest('.listline').hide(); }) }) $('.lb-detail').find('.listline.group').each(function(){ $(this).find('.del').click(function(){ $(this).closest('.box1').find('.listline.group').hide(); }) }) /* resize ------------------------------------------------------------*/ var _resize = function () { winW = $win.width(); winH = $win.height(); docH = $(document).height(); _scroll = $(window).scrollTop(); scrollBottom = $(window).scrollTop() + $(window).height(); headerH = $('header').height(); // promoPos = $('#promo').offset().top; promoscroll(); // scrollthispage(); navde(); } $win.scroll(scrollPage); _resize(); $win.resize(function () { _resize(); }); var windowHeight = $(window).height(); // Resize Event $(window).resize(function () { // Check window width has actually changed and it's not just iOS triggering a resize event on scroll if ($(window).width() != windowHeight) { // Update the window width for next time windowHeight = $(window).width(); // Do stuff here _resize(); } }); }; $(function () { //$('#myheader').load('include/header.html', function() { // if ($('.wrapper').hasClass('com')) { // $('#myheader').find('.nav').find('ul').find('li:nth-child(2)').hide(); // $('#myheader').find('.nav').find('ul').find('li:nth-child(3)').hide(); // $('#myheader').find('.nav').find('ul').find('li:nth-child(6)').hide(); // } //}); //$('#myheader').load('cdn/include/header.html'); //$('#myfooter').load('cdn/include/footer.html'); //$('#_foldheader').load('cdn/include/page_header_fold.html'); //$('#rulesubnav').load('cdn/include/rule_subnav_fold.html'); //$('#_tabheader').load('cdn/include/page_header_tab.html'); //$('#tabsubnav').load('cdn/include/rule_subnav_tab.html'); //$('#_waheader').load('cdn/include/page_header_wa.html'); //$('#wasubnav').load('cdn/include/rule_subnav_wa.html'); // script(); var imagesLoaded = loading(); imagesLoaded.loadfunc(); imagesLoaded.callback = function () { script(); }; });