index-list.js 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. let userAgent;
  2. let isSafari = false;
  3. let browserName;
  4. window.onload = function(){
  5. //window.scrollBy(0, 1);
  6. /* if(screen.width >= 901){
  7. window.location.href = "https://www2.hhh.com.tw/";
  8. } */
  9. userAgent = navigator.userAgent;
  10. detectBrowser(userAgent);
  11. detectDirection ();
  12. let result;
  13. }
  14. let over = document.querySelector('.infoContent__navBlock').offsetTop;
  15. function detectBrowser(agent){
  16. if(userAgent.match(/chrome|chromium|crios/i)){
  17. browserName = "chrome";
  18. }else if(userAgent.match(/firefox|fxios/i)){
  19. browserName = "firefox";
  20. } else if(userAgent.match(/safari/i)){
  21. browserName = "safari";
  22. }else if(userAgent.match(/opr\//i)){
  23. browserName = "opera";
  24. } else if(userAgent.match(/edg/i)){
  25. browserName = "edge";
  26. }else{
  27. browserName="No browser detection";
  28. }
  29. if(browserName === 'safari'){
  30. isSafari = true;
  31. }
  32. console.log(isSafari);
  33. }
  34. function detectDirection () {
  35. let height = (window.screen.width * 2) / 3;
  36. $('.sec-02 .slide-item').css('height', `${height}px`);
  37. let topHeight = (window.screen.width * 30) / 131;
  38. $('.sec-00 .slide-item').css('height', `${topHeight}px`);
  39. $('.sec-00 .container-fluid').css('height', `${topHeight}px`);
  40. }
  41. window.addEventListener('scroll', fixedOnScroll);
  42. const navBlock = document.querySelector('.infoContent__navBlock');
  43. function fixedOnScroll() {
  44. if(window.innerHeight < window.innerWidth){
  45. } else {
  46. detectDirection ();
  47. }
  48. if(window.pageYOffset >= over){
  49. navBlock.classList.add('tab_sticky');
  50. } else if(window.pageYOffset < over) {
  51. navBlock.classList.remove('tab_sticky');
  52. }
  53. }
  54. $('.navbar-toggler').click(function(){
  55. $(".sec-menu").css('display', 'block');
  56. $(".wholeBody").css('overflow-y', 'hidden');
  57. $('.sec-menu-block').addClass('slidein');
  58. $('.sec-menu-block').removeClass('slideout');
  59. });
  60. $('.navbar-back').click(function(){
  61. $(".sec-menu").css('display', 'none');
  62. $(".wholeBody").css('overflow-y', 'scroll');
  63. $('.sec-menu-block').removeClass('slidein');
  64. $('.sec-menu-block').addClass('slideout');
  65. });
  66. $('.subexpand').click(function(){
  67. $(this).parent().next().toggleClass('show');
  68. $(this).parent().toggleClass('show');
  69. });
  70. $('.navbar-search').click(function(){
  71. $(".sec-search").css('display', 'block');
  72. $(".wholeBody").css('overflow-y', 'hidden');
  73. })
  74. $('.navbar-backs').click(function(){
  75. $(".sec-search").css('display', 'none');
  76. $(".wholeBody").css('overflow-y', 'scroll');
  77. });
  78. $('.navbar-back-fav').click(function(){
  79. $(".sec-favor").css('display', 'none');
  80. })
  81. $('.btn-gotop').click(function () {
  82. $('html, body').animate({
  83. scrollTop: 0
  84. }, 500)
  85. });
  86. $(window).scroll(function() {
  87. if ( $(this).scrollTop() > 500 ){
  88. $('.fixed-btn').fadeIn(222);
  89. $('.freeCall').fadeIn(222);
  90. } else {
  91. $('.fixed-btn').stop().fadeOut(222);
  92. $('.freeCall').stop().fadeOut(222);
  93. }
  94. }).scroll();
  95. const searchBtn = document.querySelector('.searchBtn');
  96. const searchBar = document.querySelector('.searchBar');
  97. const searchHotLink = document.querySelectorAll('.sec-search-hots__link');
  98. searchBtn.addEventListener('click', search);
  99. searchBar.addEventListener('keyup', pressSearch);
  100. function search() {
  101. if(searchBar.value == '') {
  102. window.location.href = 'https://m.hhh.com.tw/search/lists/case/';
  103. } else {
  104. window.location.href = `https://m.hhh.com.tw/search/lists/case/${searchBar.value}-keyword/`;
  105. }
  106. }
  107. function pressSearch(e) {
  108. if (e.keyCode === 13) {
  109. e.preventDefault();
  110. search();
  111. }
  112. }
  113. searchHotLink.forEach((item, i) => {
  114. item.addEventListener('click', function() {
  115. window.location.href = `https://m.hhh.com.tw/search/lists/case/${this.textContent}-keyword/`;
  116. })
  117. })
  118. document.addEventListener('lazybeforeunveil', function(e){
  119. var bg = e.target.getAttribute('data-bg');
  120. if(bg){
  121. e.target.style.backgroundImage = 'url(' + bg + ')';
  122. }
  123. });
  124. $('.mb__infoCard__more').click(function() {
  125. $(this).hide();
  126. $('.other').css('display', 'block');
  127. over = document.querySelector('.infoContent__navBlock').offsetTop;
  128. })