/*
* In this example we will only customize the document's scrolling,
* but the API fully supports every custom scrollable container
*/
function init() {
/*
* We inform the API which element controls document scrolling
* (useful for scenarios like the body element, a custom container,
* a framework-specific container, etc...)
*/
uss.setPageScroller(window);
/**
* This API function enables anchors'
* smooth-scrolling to their respective sections
*/
uss.hrefSetup();
/**
* This API function sets the easing of the pageScroller (that we set to window) to a
* medium speed(the "QUART" part) ease-in-out function that lasts exactly 1 second.
*/
uss.setStepLengthCalculator(EASE_IN_OUT_QUART(1000));
/**
* This API function allows us to stop the scrolling within a container.
* In this case, we want scrolling to cease
* if the user navigates the document via mousewheel.
*/
window.addEventListener(
"wheel",
() => uss.stopScrolling(window)
);
}
/*
* IGNORE THIS SECTION.
* It pertains to the stackoverflow workaround for module support.
* Essentially, it loads the init function when the document finishes loading and the module is imported.
* For more details, refer to this discussion: https://meta.stackoverflow.com/questions/389108/support-javascript-es6-modules-in-code-snippets
*/
document.addEventListener("readystatechange", () => document.readyState === "complete" && init());
/* Purely stylistic; unnecessary for the API */
html, body {
margin: 0;
}
nav {
display: flex;
justify-content: center;
position: fixed;
margin-top: 0;
width: 100vw;
}
nav > a {
display: flex;
align-items: center;
justify-content: center;
color: white;
text-decoration: none;
height: 20vh;
width: 15vw;
background: rgba(20,20,20,0.5);
transition: all 0.3s;
}
nav > a:hover {
background: rgba(20,20,20,0.6);
}
.horizontal-container {
display:flex;
}
.page {
width: 100vw;
height: 100vh;
flex-shrink: 0;
}
#to1 {
background: linear-gradient(135deg, rgba(2,0,36,1) 0%, rgba(9,9,121,1) 0%, rgba(0,212,255,1) 100%);
}
#to2 {
background: linear-gradient(225deg, rgba(121,9,9,1) 0%, rgba(255,42,0,1) 100%);
}
#to3 {
background: linear-gradient(45deg, rgba(227,176,7,1) 0%, rgba(255,239,0,1) 100%);
}
#to4 {
background: linear-gradient(315deg, rgba(7,101,6,1) 0%, rgba(0,255,98,1) 100%);
}
<html>
<head>
<!-- Integrate the API -->
<script src = "https://cdn.jsdelivr.net/npm/universalsmoothscroll@latest/universalsmoothscroll-min.js"></script>
<!-- Include the API's easing library (optional) -->
<script src = "https://cdn.jsdelivr.net/npm/universalsmoothscroll@latest/universalsmoothscroll-ease-functions-min.js" type = "module"></script>
<!--
DISREGARD THIS PART.
Aids the stackoverflow workaround for module functionality.
Imports the module and converts the import into a global variable.
Refer to this discussion for further insights: https://meta.stackoverflow.com/questions/389108/support-javascript-es6-modules-in-code-snippets
-->
<script type = "module">
import {EASE_IN_OUT_QUART} from "https://cdn.jsdelivr.net/npm/universalsmoothscroll@latest/universalsmoothscroll-ease-functions-min.js";
window.EASE_IN_OUT_QUART = EASE_IN_OUT_QUART;
</script>
</head>
<body>
<nav> <!-- header -->
<a href="#to1"><p>Blue</p></a>
<a href="#to2"><p>Red</p></a>
<a href="#to3"><p>Yellow</p></a>
<a href="#to4"><p>Green</p></a>
</nav>
<!-- Website pages -->
<div class="horizontal-container">
<div id="to1" class="page"></div>
<div id="to2" class="page"></div>
</div>
<div class="horizontal-container">
<div id="to3" class="page"></div>
<div id="to4" class="page"></div>
</div>
</body>
</html>