Skip to content

Instantly share code, notes, and snippets.

@ahmadthedev
Created November 24, 2021 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ahmadthedev/003e948ad533545b36e307709a6974e9 to your computer and use it in GitHub Desktop.
Save ahmadthedev/003e948ad533545b36e307709a6974e9 to your computer and use it in GitHub Desktop.
// Guideline
// Parent div after body `.prnt_sti`
<div class="prnt_sti">
<div class="container">
<div class="sticky-form">
<div class="sticky-form-inner">
</div>
</div>
</div>
</div>
<style>
.container {
position: relative;
}
.sticky-form {
right: 0;
}
.sticky-form-inner {
position: sticky;
top: 124px;
}
</style>
<script>
function sidebarSticky() {
height = jQuery('.prnt_sti').height();
if( jQuery(window).width() >= 768 ) {
jQuery('.sticky-form').css({'height':height-100,'position':'absolute','top':'-180px'});
} else {
jQuery('.sticky-form').css({'height':'auto','position':'relative','top':'auto'});
}
}
window.addEventListener('load', function(){
sidebarSticky();
});
window.addEventListener('resize', function(){
sidebarSticky();
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment