Любой элемент прилипает по id script

Добавить в Custom JavaScript before редактора

const target = document.getElementById("target");
const container = target.parentElement;
const offsetTop = target.offsetTop;

window.addEventListener("scroll", function () {
  const scrollY = window.pageYOffset;
  const containerTop = container.offsetTop;
  const containerHeight = container.offsetHeight;
  const containerBottom = containerTop + containerHeight;
  const targetHeight = target.offsetHeight;

  // Если скролл меньше позиции блока — позиция обычная
  if (scrollY < offsetTop) {
    target.style.position = "static";
    target.style.top = "";
    target.style.width = "100%";
  }

  // Если блок должен быть фиксирован, и не достиг низа контейнера
  else if (scrollY + targetHeight + 80 < containerBottom) {
    target.style.position = "fixed";
    target.style.top = "80px";
    target.style.width = "30%";
  }

  // Когда дошли до низа родителя — пусть блок остаётся внутри, как будто "уезжает"
  else {
    // Устанавливаем абсолютное позиционирование относительно родителя
    target.style.position = "absolute";
    target.style.top = (containerHeight - targetHeight) + "px";
    target.style.width = "100%";
  }
});