Skip to content

jQuery plugin for making an element fixed when it goes out of view.

License

Notifications You must be signed in to change notification settings

josterpi/jquery-scrollfix

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ScrollFix

jQuery plugin for making an element fixed when it goes out of view.

Demo

See demo.html for an example.

Features

  • detecting when an element goes out of view and making it fixed
  • replacing the element with an invisible clone that will temporarily occupy the original spot
  • updating size and position of the fixed element

Browser support

Tested in Mozilla Firefox, Google Chrome, Safari, Opera and MSIE 7+

Usage

The plugin provides a single jQuery method you can use:

$(element).scrollFix([options])

  • element - element that will be fixed
  • options - object with various settings (see list below)

Returns: an instance of Shira.ScrollFix.Watcher or false if no element was given / matched.

Options

Name Default Description
fixClass "scroll-fix" Class added to the element when it is fixed.
fixTop 0 Top offset of the fixed element.
fixOffset 0 Offset aplied when detecting whether to fix the element.
unfixOffset 0 Offset aplied when detecting whether to unfix the element.
syncSize true Update element's size when it is fixed.
syncPosition true Update element's position when it is fixed.
style true Apply position: fixed and top: ..px directly to the element when it is fixed. Disable this if you wish to style the element through your own CSS rules using the fixClass (example: #myElement.scroll-fix {position: fixed;}).
onUpdateFixed null Custom function to call when the fixed element is updated. The function is passed an instance of Shira.ScrollFix.Watcher.

About

jQuery plugin for making an element fixed when it goes out of view.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • HTML 73.0%
  • JavaScript 27.0%