Advertisement
inodorotnuk

sticky headline

Mar 24th, 2020
598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function initHeadline_sticky()
  2.       {
  3.         console.log('[DFP] initiate Headline stickiness');
  4.             var dfpOnceSticky = false, hlStart = 0, hlStickyTimer;
  5.         document.addEventListener("scroll", function(){
  6.             var dfpHL = document.getElementById("div-gpt-ad-liputan6-hl");
  7.             var hlPos = dfpHL.getBoundingClientRect();
  8.             if(!dfpOnceSticky && hlPos.top<=10){
  9.                 hlStart = dfpHL.offsetTop;
  10.                 dfpHL.classList.add("dfp-hl-sticky");
  11.                 dfpOnceSticky = true;
  12.                 dfp_videoHLStickyState = dfpOnceSticky;
  13.                 hlStickyTimer = window.setTimeout(function() {
  14.                     dfpHL.style.marginTop = -(dfpHL.clientHeight)+"px"
  15.                     setTimeout(function() {
  16.                         dfpHL.classList.remove("dfp-hl-sticky");
  17.                         dfpHL.style.marginTop = "0px";
  18.                     }, 700);
  19.                 }, 5000);
  20.             }
  21.             if(dfpOnceSticky && window.scrollY < (hlStart-70) && hlStickyTimer){
  22.                 window.clearTimeout(hlStickyTimer);
  23.                 dfpHL.classList.remove("dfp-hl-sticky");
  24.                 dfpHL.style.marginTop = "10px";
  25.             }
  26.         });
  27.       }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement