Created
August 17, 2021 22:01
-
-
Save pingram3541/3f0a179aec732301bed3bb4a46a92e40 to your computer and use it in GitHub Desktop.
Sticky Back to Top JavaScript using Element ID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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