By Stephen Walker

Share

This creates a floating container. More to come.


.fixed--bottom{
  position:fixed!important;
  bottom:2rem;
   transform: translateY(130px); /* Start off the screen */
  transition: transform 0.75s ease-in-out; /* Smooth transition for sliding effect */
}
.fixed--bottom--left{
  left:20px;
}
.fixed--bottom-center{
  left:50%;
  transform:translateX(-50%)
}

.show-floater .fixed--bottom{
  transform: translateY(0);
   z-index:10000;
}
.btn-tall{
  height:100%
}
let lastScrollTop = 0; // Keep track of the last scroll position
window.addEventListener('scroll', function() {
let currentScroll = window.pageYOffset || document.documentElement.scrollTop;
const body = document.querySelector('body');
const floaterWrapper = document.querySelector('.fixed--bottom');
if (currentScroll > lastScrollTop) {
// Scrolling down
if (currentScroll > 100) {
// Slide up after scrolling down 100px
body.classList.add('show-floater');
}
} else {
// Scrolling up
// Slide off the screen
body.classList.remove('show-floater');
}
lastScrollTop = currentScroll <= 0 ? 0 : currentScroll; // For Mobile or negative scrolling
}, false);

Originally published on 4 weeks ago

Get your image to fill the space

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

RELATED Snippets

  • Avada, CSS

    This is a style I recently used on my blog post title bar to have the feature image fill the column without having to use a background image.

  • JavaScript

    Remove the image title when you hover over an image.

  • Avada, CSS

    I have seen some tables of contents around the web that use what appears as a left border, and the border color changes when highlighted. This feature is missing from the current version of Avada, so I created CSS styling to do this. It works best with a single-level list. […]

  • Avada

    The social sharing element has some styles that prevent stacking them in a column. This CSS will resolve this. Just assign the class to each instance.

  • Avada, CSS

    This gives the default RSS feed widget a more polished appearance.

  • Avada

    The Toggle Element styling leaves a bit to be desired as it applies hover effects to the entire block and not just the header and the panel. This should override that behavior but still takes advantage of the settings, thanks to the use of CSS variables. Example