Keep your HC-Sticky instance saved in a variable so you can utilize HC-Sticky's API:
var sticky = new hcSticky('.this-sticks', {
stickTo: 'main'
});
sticky.reinit();
OR retrieve it using jQuery.data(...)
:
jQuery('.this-sticks').hcSticky({
stickTo: 'main'
});
jQuery('.this-sticks').data('hcSticky').reinit();
Illustration 1:
Implementing new hcSticky(...)
jQuery(document).ready(function() {
var sticky = new hcSticky('.this-sticks', {
stickTo: 'main'
});
sticky.reinit();
});
body {
margin-top: 300px;
}
header {
height: 300px;
background: black;
position: fixed;
top: 0;
right: 0;
left: 0;
}
section {
height: 100vh;
background: #ccc;
}
footer {
height: 400px;
background: black;
}
.this-sticks {
background: blue;
height: 100px;
}
<!doctype html>
<html lang="en>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>HC Sticky Example</title>
</head>
<body>
<div>
<header></header>
<main>
<section class="this-sticks">sticky</section>
<section></section>
</main>
<footer></footer>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://rawgit.com/somewebmedia/hc-sticky/master/dist/hc-sticky.js"></script>
</body>
</html>
Illustration 2:
Utilizing jQuery(...).hcSticky(...)
jQuery(document).ready(function() {
jQuery('.this-sticks').hcSticky({
stickTo: 'main'
});
jQuery('.this-sticks').data('hcSticky').reinit();
});
body {
margin-top: 300px;
}
header {
height: 300px;
background: black;
position: fixed;
top: 0;
right: 0;
left: 0;
}
section {
height: 100vh;
background: #ccc;
}
footer {
height: 400px;
background: black;
}
.this-sticks {
background: blue;
height: 100px;
}
<!doctype html>
<html lang="en>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>HC Sticky Example</title>
</head>
<body>
<div>
<header></header>
<main>
<section class="this-sticks">sticky</section>
<section></section>
</main>
<footer></footer>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://rawgit.com/somewebmedia/hc-sticky/master/dist/hc-sticky.js"></script>
</body>
</html>