Skip to content

Instantly share code, notes, and snippets.

@Jermolene
Created April 15, 2022 13:14
Show Gist options
  • Save Jermolene/3acf7240235d8d82d3a97c813b53cad0 to your computer and use it in GitHub Desktop.
Save Jermolene/3acf7240235d8d82d3a97c813b53cad0 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Scrolling Test</title>
<script>
</script>
</head>
<body>
<div style="background:red;height:100px;overflow:scroll;">
<div style="background:grey;height:100px;overflow:scroll;">
</div>
<div style="background:green;height:100px;overflow:scroll;">
This is some content.<br>
<svg>
<rect width="100" height="700" style="fill:red;stroke:black;stroke-width:1;"></rect>
</svg>
<div id="target">
Scroll to here!
</div>
</div>
<div style="background:grey;height:100px;overflow:scroll;">
</div>
</div>
Clicking this button will scroll two containers to get to the target:
<button onclick="document.querySelectorAll('#target')[0].scrollIntoView({behavior: 'smooth'});">
Scroll to the target
</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment