elin-r
2/20/2018 - 10:18 PM

Wordpress – Scroll div to certain position w/ addClass + CSS

.sticky {
position: fixed;
top: 250px;
margin: 0px 0px 0px 43px;
}

@media (max-width: 768px) {
.sticky {
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
margin: 0px;
}
}
window.onscroll = function() {stickySplash()};
window.onresize = function() {stickySplash()};

var $document = jQuery(document);

function stickySplash() {
var $view = jQuery( window ).height();
  if ( ($document.scrollTop() >= $view - 60) ) {
    jQuery("#splash").removeClass('sticky');
  }
  else if ($document.scrollTop() <= $view - 60) {
    jQuery("#splash").addClass('sticky');
  }
}