Skip to content

Instantly share code, notes, and snippets.

@pingram3541
Created August 17, 2021 22:01
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 pingram3541/3f0a179aec732301bed3bb4a46a92e40 to your computer and use it in GitHub Desktop.
Save pingram3541/3f0a179aec732301bed3bb4a46a92e40 to your computer and use it in GitHub Desktop.
Sticky Back to Top JavaScript using Element ID
<!--
Title: Scroll Top
Type: elementor_snippet
Author: Website Admin
Last edited: 2021-04-02 18:07:14
Note: This was added by Elementor, just copy script code below.
Instructions: Add to any site or via Elementor Custom Code feature (Body -> End),
then use "up" as the id of the trigger element in your design
--- The comment is visible only for administrators ---
-->
<script type="text/javascript">
var body = document.body;
var trigger = document.getElementById('up');
trigger.addEventListener('click', function( event ){
event.preventDefault();
var elementPosition = body.offsetTop;
window.scrollTo(0, elementPosition);
}, false);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment