Fix Element Parent Scroll - Download Fix Element Within Parent Container On Scroll - sticky.jquery.js

Download Fix Element Within Parent Container On Scroll – sticky.jquery.js

Posted on

This time I will share jQuery Plugin and tutorial about Fix Element Within Parent Container On Scroll – sticky.jquery.js, hope it will help you in programming stack.

Fix Element Parent Scroll - Download Fix Element Within Parent Container On Scroll - sticky.jquery.js
File Size: 4.81 KB
Views Total: 2046
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

sticky.jquery.js is a small jQuery plugin for making an element always be fixed within its parent container when scrolling down.

The plugin sticks the element to the top of the webpage until it reaches a ‘Stop’ element.

A typical use of this plugin is to make a widget always stay visible within the sidebar.

It also has the ability to stop the ‘Sticky’ behavior on mobile devices to prevent breaking the page layout.

How to use it:

1. Insert the sticky.jquery.js script after the latest version of jQuery JavaScript library (slim build).

2         integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
3         crossorigin="anonymous">
4 </script>
5 <script src="sticky.jquery.js"></script>

2. Create a ‘Stop’ element at which point the sticky element stops the ‘Sticky’ behavior.

1 <div class="main-content-end-padding">
2   <!-- This content will mark the stop of sticky content -->
3 </div>

3. Call the function on your element which should be sticky as you scroll past it.

1 <div class="sticky-content">
2   <p>Sticky content</p>
3 </div>
1 (function(){
2   $('.sticky-content').StickyDL();
3 })()

4. Available options to customize the plugin.

01 $('.sticky-content').StickyDL({
02  
03   // start position
04   paddingTop: 100,
05  
06   // selector of Stop element
07   heightRefElement: '.main-content-end-padding',
08  
09   // optional Top/Bottom distances
10   optionalBottomFix: 0,
11   optionalTopFix: 0
12    
13 });

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

source : jquery.net