Advertisement
petar_bonov

admin 4: banner preview fix

May 25th, 2023
610
0
19 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.37 KB | None | 0 0
  1. <style>
  2. table {
  3.     overflow: hidden;
  4. }
  5. table td:first-child {
  6.     white-space: nowrap;    
  7. }
  8.    
  9. table tr:first-child td {
  10.     writing-mode: vertical-lr;
  11.     transform: rotate(-180deg);
  12.     text-align: left;
  13. }
  14. table tr:first-child td b {
  15.     display: inline-block;
  16.     font-weight: normal;
  17.     letter-spacing: 0.1px;
  18. }
  19. table tr:first-child td b a {
  20.     padding: 5px 2px 0 2px;
  21. }
  22.  
  23. table .banner-preview {
  24.     display: none;
  25.     position: absolute;
  26.     bottom: 105%;
  27.  
  28.     writing-mode: horizontal-tb;
  29.     transform: rotate(-180deg) translateX(50%);
  30.  
  31.     background: white;
  32.     border: 1px solid #888;
  33.     padding: 5px;
  34. }
  35.  
  36. table .banner-preview span {
  37.     display: inline-block;
  38.     color: black;
  39.     margin-top: 5px;
  40.     font-size: 14px;
  41. }
  42.  
  43. table a:hover .banner-preview {
  44.     display: block;
  45. }
  46. </style>   
  47.  
  48. <script>
  49. const BASE_FOLDER = "https://st.gsmarena.com/imgroot/static/banners/self/";
  50.  
  51. window.addEventListener("DOMContentLoaded", function () {
  52.     const links = document.querySelectorAll("table a");
  53.     for (const link of links) {
  54.         const match = link.innerText.match(/\[[^\]]+\](.+)/);
  55.         if (!match) continue;
  56.  
  57.         const container = document.createElement("div");
  58.         container.classList = "banner-preview";
  59.  
  60.         const image = document.createElement("img");
  61.         image.src = BASE_FOLDER + match[1];
  62.  
  63.         const text = document.createElement("span");
  64.         text.innerText = link.innerText;
  65.  
  66.         container.appendChild(image);
  67.         container.appendChild(text);
  68.         link.appendChild(container);
  69.  
  70.         link.onmouseenter = function () {
  71.             const banner = this.querySelector(".banner-preview");
  72.             const rect = banner.getBoundingClientRect();
  73.             const image = banner.querySelector("img")
  74.            
  75.             setTimeout(function () {
  76.                 if (rect.right > screen.width) {
  77.                     banner.style.left = (rect.right - screen.width + 30) + "px";
  78.                 } else if (rect.left < 0) {
  79.                    banner.style.left = (rect.left) + "px";
  80.                } else {
  81.                    banner.style.left = "";
  82.                }
  83.            }, 0);
  84.        };
  85.        link.onmouseleave = function () {
  86.            const banner = this.querySelector(".banner-preview");
  87.            banner.style.left = "";
  88.        };
  89.    }
  90. });
  91. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement