index.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. let userAgent;
  2. let isSafari = false;
  3. let browserName;
  4. // pagination variables
  5. let num_per_page = 9;
  6. let n = 0;
  7. let totalPages = {
  8. intro: 0,
  9. video: 0,
  10. columns: 0,
  11. vr360: 0,
  12. company: 0,
  13. };
  14. window.onload = function(){
  15. if(screen.width < 900){
  16. window.location.href = "../index_designerList_mb.html";
  17. }
  18. userAgent = navigator.userAgent;
  19. detectBrowser(userAgent);
  20. detectDirection ();
  21. let result;
  22. let designer;
  23. let id = 0;
  24. $.ajax({
  25. method: "GET",
  26. url: "./json/realtime.json",
  27. dataType: "json",
  28. }).done(function (msg) {
  29. result = [...msg];
  30. renderSec00(result);
  31. });
  32. }
  33. function detectDirection () {
  34. let height = (window.screen.width * 5) / 12;
  35. console.log(height);
  36. $('.sec-02 .slide-item').css('height', `${height}px`);
  37. }
  38. function detectBrowser(agent){
  39. if(userAgent.match(/chrome|chromium|crios/i)){
  40. browserName = "chrome";
  41. }else if(userAgent.match(/firefox|fxios/i)){
  42. browserName = "firefox";
  43. } else if(userAgent.match(/safari/i)){
  44. browserName = "safari";
  45. }else if(userAgent.match(/opr\//i)){
  46. browserName = "opera";
  47. } else if(userAgent.match(/edg/i)){
  48. browserName = "edge";
  49. }else{
  50. browserName="No browser detection";
  51. }
  52. if(browserName === 'safari'){
  53. isSafari = true;
  54. }
  55. console.log(isSafari);
  56. }
  57. function renderSec00(data) {
  58. let temp = data[0]['data'];
  59. renderBannerStr('sec-00__slider', temp);
  60. $(".sec-00__slider").slick({
  61. dots: false,
  62. speed: 800,
  63. autoplay: true,
  64. autoplaySpeed: 5000,
  65. arrows: true,
  66. prevArrow: '<button type="button" class="slick-prev"><i class="fas fa-chevron-left" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>',
  67. nextArrow: '<button type="button" class="slick-next"><i class="fas fa-chevron-right" style="font-size: 32px;color: white;transform: translateY(-10px);"></i></button>'
  68. });
  69. }
  70. function renderBannerStr(sec, data) {
  71. let str = '';
  72. for(let i = 0; i < data.length; i++){
  73. if(data[i]['Dwebp'] && !isSafari) {
  74. str+= `<img class="${sec}-${i+1} slide-item" onclick="window.open('${data[i]['link']}');" style="background-image: url('${data[i]['Dwebp']}');" data-bg="${data[i]['Dwebp']}"></img>`
  75. } else {
  76. str+= `<img class="${sec}-${i+1} slide-item" onclick="window.open('${data[i]['link']}');" style="background-image: url('${data[i]['DimgUrl']}');" data-bg="${data[i]['DimgUrl']}"></img>`
  77. }
  78. }
  79. $(`.${sec}`).html(str);
  80. }
  81. let sticky = document.querySelector('.sec-00').offsetHeight;
  82. window.addEventListener('scroll', fixedOnScroll);
  83. const navbar = document.querySelector('.navbar-main');
  84. function fixedOnScroll() {
  85. if(window.pageYOffset >= 344){
  86. navbar.classList.add('sticky');
  87. } else {
  88. navbar.classList.remove('sticky');
  89. }
  90. }
  91. $(window).scroll(function() {
  92. if ( $(this).scrollTop() > 800 ){
  93. $('.fixed-btn').fadeIn(222);
  94. } else {
  95. $('.fixed-btn').stop().fadeOut(222);
  96. }
  97. }).scroll();
  98. $('.btn-gotop').click(function () {
  99. $('html, body').animate({
  100. scrollTop: 0
  101. }, 500)
  102. });
  103. $('.sec-00__close').click(function(){
  104. $(this).css('display', 'none');
  105. $('.sec-00').addClass('bannerClose');
  106. //$('.sec-02').css('padding-top', '53px');
  107. sticky = 0;
  108. });
  109. document.addEventListener('lazybeforeunveil', function(e){
  110. var bg = e.target.getAttribute('data-bg');
  111. if(bg){
  112. e.target.style.backgroundImage = 'url(' + bg + ')';
  113. }
  114. });