jQuery Sticky Element on Scroll Plugin: HC-Sticky

Add-ons
2026-08-03 12:27 4 次浏览 • 0 次下载 14.9KB
jQuery Sticky Element on Scroll Plugin: HC-Sticky

HC-Sticky

hc-sticky is a jQuery plugin for fixing elements during page scrolling. It supports cross-browser compatibility and can fix specified elements to the viewport while the page is scrolling. This sticky element plugin is available in both JavaScript and jQuery versions.

Installation

You can install the hc-sticky plugin using npm or bower.

1
2
npm: npm install --save hc-sticky
bower: bower install --save hc-sticky

Usage

Include jQuery and the hc-sticky.js file in your page.

1
2
<script src="js/jquery.min.js"></script>
<script src="js/hc-sticky.js"></script>

Initialize the Plugin

This sticky element plugin is available in both JavaScript and jQuery versions. Their initialization methods are as follows:

JavaScript Version:

1
2
3
var Sticky = new hcSticky('#element', {
stickTo: '#content'
});

jQuery Version:

1
2
3
4
5
jQuery(document).ready(function($) {
$('#element').hcSticky({
stickTo: '#content'
});
});

Configuration Parameters

Available configuration options for this jQuery sticky element on page scroll plugin:

ParametersDefault ValueTypeDescription
top0intThe distance between the top of the viewport and the fixed target element.
bottom0intThe distance between the bottom of the viewport and the fixed target element.
innerTop0intThe distance from the top of the element inside the fixed element.
innerStickernullstring / element objectFor elements inside the fixed element, this takes priority over innerTop.
bottomEnd0intThe distance from the bottom of the reference element at which scrolling stops.
stickTonull (parent element)string / element objectThe container to which the fixed element is attached.
followScrolltruebooleanIf set to false, the fixed element will not follow page scrolling when its height exceeds the viewport height.
stickyClass'sticky'stringThe CSS class added to the scrolling element.
queriesnullobjectAn object containing responsive breakpoints.
onStartnullfunctionCallback function triggered when the element becomes fixed.
onStopnullfunctionCallback function triggered when the element stops following the scroll.
onBeforeResizenullfunctionTriggered before the dimensions of the fixed element are changed.
onResizenullfunctionTriggered when the dimensions of the fixed element are changed.
resizeDebounce100intLimit the rate at which the HC Sticky can fire on window resize.

Methods

Available methods for this jQuery sticky element on page scroll plugin:

MethodsAccepts a value.Description
optionsstringReturns the current configuration.
updateobjectUpdates the configuration parameters.
reinitN/ARecalculates the dimensions and position of the fixed element.
detachN/ADetaches HC-Sticky from the element.
attachN/AAttaches HC-Sticky to the element.
destroyN/ADestroys the plugin.
星河码客

发现和分享优质开源项目,传承互联网精神,为开发者服务。

关于本站

联系我们

微信/广告合作:ITcloub (备注星河码客)

免责声明:本站资源版权归原作者所有,仅供学习与交流。如有侵权,请通过「关于我们 - 侵权投诉」联系删除。

Powered by Nuxt · Deployed on Cloudflare