From 5d980f19b827821231995809f4b472f7312c3e25 Mon Sep 17 00:00:00 2001 From: rulingcom Date: Mon, 6 Feb 2023 23:42:13 +0800 Subject: [PATCH] Fix bug. --- assets/javascripts/app.js | 95 ++++----------------------------------- 1 file changed, 9 insertions(+), 86 deletions(-) diff --git a/assets/javascripts/app.js b/assets/javascripts/app.js index 9144268..24885cd 100644 --- a/assets/javascripts/app.js +++ b/assets/javascripts/app.js @@ -11,7 +11,11 @@ this.replaceWith(new_html); } }); - function fix_first_element() { + function fix_first_element(force_fix) { + if(!force_fix && window.already_fix_first_element){ + return; + } + window.already_fix_first_element = false; if (!window.has_topest_banner) { $('.downIcon').css('display','none'); var first_element = $('.header-banner'); @@ -24,7 +28,7 @@ } if(first_element.length != 0){ first_element.css("margin-top", ""); - var ele_offset = first_element[0].getBoundingClientRect().top; + var ele_offset = first_element[0].getBoundingClientRect().top + document.documentElement.scrollTop; if(first_element.parents('.kenjohn.navFixed').length == 0) ele_offset -= window.top_barrier_height; if(ele_offset < 0){ @@ -37,6 +41,7 @@ $("#onesection").css("margin", "0"); $('.layout-content-inner .row, .layout-content-inner .row > [class*="col-"]').css("padding", "0"); } + window.already_fix_first_element = true; } function initdata1 () { window.temp_scrollY = window.pageYOffset; @@ -63,6 +68,7 @@ } var navFixed = $('.kenjohn.navFixed'); window.top_barrier_height = (navFixed.length ? navFixed.height() : 0) + $('#orbit-bar').height(); + fix_first_element(); } // 初始函數: 把所有的程式碼都包在init裡面,方便在之後的jQuery ready 函數裡一次呼叫 function init() { @@ -463,7 +469,6 @@ // 在所有的頁面(包含首頁)執行下面這幾個函數 window.has_topest_banner = ($('[data-pp="300"] .w-ad-banner').length != 0); initdata1(); - fix_first_element(); orbit.sitemenuDropdown(); orbit.goBackTop('top', 800); orbit.plugins.bullEye(); @@ -486,7 +491,7 @@ $(window).resize(function() { var navFixed = $('.kenjohn.navFixed'); window.top_barrier_height = (navFixed.length ? navFixed.height() : 0) + $('#orbit-bar').height(); - fix_first_element(); + fix_first_element(true); if ($(window).outerWidth() < 769) { if (resizeTimer) clearTimeout(resizeTimer); $('.outdropdowns').before($('.header-nav')); @@ -514,88 +519,6 @@ // }else{ // $('.header-buttom').appendTo($('.dropdowns')); // } - function forFreeGo() { - // 幫有連結目的之所有a標籤加上title - for(var i=0;i<$('a').length;i++){ - if($('a').eq(i).attr("href") != "" || $('a').eq(i).attr("href") != undefined ){ - var titlestr=""; - if($('a').eq(i).attr('target')=='_self') - titlestr += '在本視窗開啟 '; - else if($('a').eq(i).attr('target') == '_blank') - titlestr += '在新視窗開啟 '; - if($('a').eq(i).attr('title') == "" || $('a').eq(i).attr('title')==undefined && $('a').eq(i).html().search('span').length==1) - titlestr += $('a').eq(i).find('>span').html().trim(); - else if($('a').eq(i).attr('title') == "" || $('a').eq(i).attr('title') == undefined){ - try{ - if($('a').eq(i).html().trim().split('>').length==2) - titlestr += $('a').eq(i).html().trim().split('>')[1].trim(); - else if($('a').eq(i).html().trim().split('>').length==3) - titlestr += $('a').eq(i).html().trim().split('>')[2].trim(); - }catch(e){}; - } - else - titlestr += $('a').eq(i).attr('title'); - if(titlestr.search('=0;i--) - if($('dd a.i-archive-files-item').eq(i).html().trim()=="") - $('dd a.i-archive-files-item').eq(i).parent('dd').remove(); - // 刪除具有空連結欄位的橫列 - for(var i = 0;i < $('*[data-list] tr td a').length ; i++) - if($('*[data-list] tr td a').eq(i).html().trim()=="") - $('*[data-list] tr td a').eq(i).parent('td').parent('tr').remove(); - // tab按鍵選到menu,會顯示下層的menu(為了符合無障礙) - /* - $('.nav-level-0>li>a').focus(function(e) { - e.stopPropagation(); - $(this).parent().focus(); - if ($(this).parent().find('.nav-level-1').hasClass('show')) { - } else { - $('.nav-level-1').removeClass('show'); - $(this).parent().find('.nav-level-1').addClass('show'); - } - }); - $('.nav-level-1>li>a').focus(function(e) { - e.stopPropagation(); - if ($(this).parent().find('.nav-level-2').hasClass('show')) { - }else{ - $('.nav-level-2').removeClass('show'); - $(this).parent().find('.nav-level-2').addClass('show'); - } - }); - $('show').parent('li').focus(); - */ - } - forFreeGo(); $(document).on('touchstart','a',function(e){ e.stopPropagation(); $(this).trigger('focus');