Advertisement
Luxup

delo-vcusa.ru: sticky

May 20th, 2024
464
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var shb = document.querySelector('.essb-mobile-sharebottom');
  2. show(shb);
  3. adjustIngredientsPosition();
  4. updateBottomPosition();
  5.  
  6. waitForElm('.bs6').then((elm) => {
  7.     const ro = new ResizeObserver(entries => {
  8.         for (let entry of entries) {
  9.             updateButtonsPosition();
  10.             adjustIngredientsPosition();
  11.             updateBottomPosition();
  12.         }
  13.     });
  14.     ro.observe(elm);
  15. });
  16.  
  17. function waitForElm(selector) {
  18.     return new Promise(resolve => {
  19.         if (document.querySelector(selector)) {
  20.             return resolve(document.querySelector(selector));
  21.         }
  22.  
  23.         const observer = new MutationObserver(mutations => {
  24.             if (document.querySelector(selector)) {
  25.                 resolve(document.querySelector(selector));
  26.                 observer.disconnect();
  27.             }
  28.         });
  29.  
  30.         observer.observe(document.body, {
  31.             childList: true,
  32.             subtree: true
  33.         });
  34.     });
  35. }
  36.  
  37. function updateBottomPosition() {
  38.     const essbMobileSharebottom = document.querySelector('.essb-mobile-sharebottom');
  39.     const targetElement = document.querySelector('.bs6');
  40.     const fixedIngredients = document.querySelector('.fixed-ingredients.visible');
  41.  
  42.     if (essbMobileSharebottom && targetElement) {
  43.         let essbHeight = essbMobileSharebottom.offsetHeight;
  44.         if (fixedIngredients) {
  45.             essbHeight += fixedIngredients.offsetHeight;
  46.         }
  47.         targetElement.style.bottom = `${essbHeight}px`;
  48.     }
  49. }
  50.  
  51. const observer = new MutationObserver(mutations => {
  52.     mutations.forEach(mutation => {
  53.         if (mutation.target.classList.contains('fixed-ingredients')) {
  54.             updateBottomPosition();
  55.         }
  56.     });
  57. });
  58.  
  59. observer.observe(document.body, {
  60.     attributes: true,
  61.     subtree: true,
  62.     attributeFilter: ['class']
  63. });
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement