Add CSS Class To Element On Scroll - jQuery scrollAddclass

File Size: 23 KB
Views Total: 1581
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Add CSS Class To Element On Scroll - jQuery scrollAddclass

The scrollAddclass jQuery plugin adds a custom CSS class to your elements when a specific part of them become visible as you scroll down the web page. Great for animating your html contents on view while scrolling.

How to use it:

1. Include the necessary jQuery library and imagesLoaded (if you want to attach the plugin to images) JavaScript library on the webpage.

<script src="/path/to/jquery.min.js"></script>
<script src="/path/to/imagesloaded.pkgd.min.js"></script>

2. Include the jquery-scrollAddClass.js script after jQuery and the scrollAddclass plugin is ready for use.

<script src="jquery-scrollAddClass.js"></script>

3. Call the function on the target element and specify the CSS class name you want to use.

$('#myElement').scrollAddClass({
  className: 'slideIn'
});

4. Apply custom CSS styles (CSS3 animations) to the element as it is scrolled into view.

.myElement {
  transition: all .4s linear;
  -webkit-transition: all .4s linear;
  -moz-transition: all .4s linear;
  -o-transition: all .4s linear;
  -ms-transition: all .4s linear;
  -ms-filter: "alpha(opacity=0)";
  opacity: 0;
  transform: translate(0, 60px);
  -webkit-transform: translate(0, 60px);
  -moz-transform: translate(0, 60px);
  -o-transform: translate(0, 60px);
  -ms-transform: translate(0, 60px)
}

.myElement.slideIn {
  transform: translate(0, 0);
  -webkit-transform: translate(0, 0);
  -moz-transform: translate(0, 0);
  -o-transform: translate(0, 0);
  -ms-transform: translate(0, 0);
  -ms-filter: "alpha(opacity=100)";
  opacity: 1
}

5. Specify the wait time before triggering the function.

$('#myElement').scrollAddClass({
  className: 'slideIn',
  timeout:100
});

This awesome jQuery plugin is developed by Black-Yamasan. For more Advanced Usages, please check the demo page or visit the official website.