Playgrounds
Snippets
Developers
Compiler
All
ActionScript
Ajax
AngularJS
Apache
AppleScript
ASP.NET
Bash
C
C#
C++
Coffee
CoffeeScript
ColdFusion
Command
CSS
Delphi
Django
ES6
GLSL
Grunt
Gulp
HAML
Haskell
HTML
iOS
Jade
Java
JavaScript
jQuery
JSX
Less
LUA
MDX
MySQL
Objective
Other
Pascal
Perl
PHP
Plain text
PowerShell
Processing
Progress
Prolog
Pseudocode
Python
Rails
RegExr
Ruby
SASS
Scala
Scheme
SCSS
SmallBASIC
Smarty
SQL
Stylus
SVG
Swift
TypeScript
VHDL
X++
XHTML
XML
Xojo
XSLT
New snippet
New playground
Sign up
Login
Upload
Playgrounds
Snippets
Developers
Sign up
Login
Playground Settings
HTML
CSS
JAVASCRIPT
HTML Preprocessor
HTML
HTML
HAML
JADE
Stuff for <head>
Save
Cancel
CSS Preprocessor
CSS
CSS
SASS
SCSS
LESS
Stylus
Quick Add
---
Animate.css
Bootstrap
Foundation
Add external resource
External CSS
Save
Cancel
Javascript Preprocessor
Javascript
Javascript
Babel
TypeScript
Coffee
Quick Add
---
Angular
Backbone
Bootstrap
D3
Ember
GreensockTweenMax
Handlebars
jQuery
jQuery UI
Knockout.js
Lodash
Modernizr
Polymer
React
React DOM
Snap.svg
Three.js
Underscore
Zepto
Add external resource
External JS
Save
Cancel
Scroll to Element
HTML
<script src="//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <div data-jumper="#one">Go To Section One</div> <div data-jumper="#two">Go to Setion Two</div> <hr> <div id="one">First Element</div> <hr> <div id="two">Second Element</div> <hr>
CSS
hr { height: 100vh; }
JAVASCRIPT
$( document ).ready(function() { $("[data-jumper^='#']").click(function(e) { var position = $($(this).attr("data-jumper")).offset().top; $("body, html").animate({scrollTop: position}, 2000); }); });
Run
Expand for more options
Login
1 Response
Simple scroll to element via jquery. I got this from codepen they were using hrefs I switched to a different identifier to avoid using the prevent default.
0
Reply?
Scott
5 years ago
1
0
1027
Share
Created by
Scott
1 Response