Execute A Function When An Element Visibility Changes jQuery scrollIntoView - Download Execute A Function When An Element's Visibility Changes - jQuery scrollIntoView

Download Execute A Function When An Element’s Visibility Changes – jQuery scrollIntoView

Posted on

This time I will share jQuery Plugin and tutorial about Execute A Function When An Element’s Visibility Changes – jQuery scrollIntoView, hope it will help you in programming stack.

Execute A Function When An Element Visibility Changes jQuery scrollIntoView - Download Execute A Function When An Element's Visibility Changes - jQuery scrollIntoView
File Size: 5.42 KB
Views Total: 6791
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

scrollIntoView is a jQuery plugin that listens for the page scroll events and fires a function when an element is scrolled into view or out.

How to use it:

1. Import the jquery.scrollintoview.js script into your webpage, after jQuery JavaScript library.

1 <script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
2 <script src="jquery.scrollintoview.js"></script>

2. In this case, we’re going to change the background colors of the webpage when the element ‘box’ is scrolled into view or out.

01 $(function () {
02  
03   var mount = function () {
04     $('body').css('background-color', 'red')
05   }
06   var unmount = function () {
07     $('body').css('background-color', '#fff')
08   }
09  
10   $('.box').scrollIntoView(mount, unmount)
11  
12 })

3. Set the once parameter (default: false) to true if you want the function to be triggered only once.

1 $('.box').scrollIntoView(mount, unmount, true)

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

source : jqueryscript.net