Smooth Scroll
How do I make an smooth scroll?
Smooth scroll experiment in pure javascript. What is a smooth scroll? How do you make a smooth scroll? This script and codes were developed by Lorenzo D'Ianni on 29 September 2022, Thursday.
Smooth Scroll - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Smooth Scroll</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <ul> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li> <li>CLICK TO SCROLL HERE</li>
</ul> <script src="js/index.js"></script>
</body>
</html>
Smooth Scroll - Script Codes CSS Codes
* { margin: 0; padding: 0; -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; -webkit-overflow-scrolling: touch; -webkit-tap-highlight-color: transparent; -moz-tap-highlight-color: transparent; tap-highlight-color: transparent;
}
ul li:nth-child(1) { color: rgba(60, 60, 80, 0.8); background: rgba(0, 0, 255, 0.03333);
}
ul li:nth-child(2) { color: rgba(120, 120, 160, 0.8); background: rgba(0, 0, 255, 0.06667);
}
ul li:nth-child(3) { color: rgba(180, 180, 240, 0.8); background: rgba(0, 0, 255, 0.1);
}
ul li:nth-child(4) { color: rgba(240, 240, 255, 0.8); background: rgba(0, 0, 255, 0.13333);
}
ul li:nth-child(5) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.16667);
}
ul li:nth-child(6) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.2);
}
ul li:nth-child(7) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.23333);
}
ul li:nth-child(8) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.26667);
}
ul li:nth-child(9) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.3);
}
ul li:nth-child(10) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.33333);
}
ul li:nth-child(11) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.36667);
}
ul li:nth-child(12) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.4);
}
ul li:nth-child(13) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.43333);
}
ul li:nth-child(14) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.46667);
}
ul li:nth-child(15) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.5);
}
ul li:nth-child(16) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.53333);
}
ul li:nth-child(17) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.56667);
}
ul li:nth-child(18) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.6);
}
ul li:nth-child(19) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.63333);
}
ul li:nth-child(20) { color: rgba(255, 255, 255, 0.8); background: rgba(0, 0, 255, 0.66667);
}
ul { position: absolute; top: 0; right: 0; bottom: 0; left: 0; width: 90%; max-width: 300px; height: 90%; overflow: auto; margin: auto; border-radius: 4px; box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
}
ul li { width: 100%; height: 80px; font: 300 12px/80px Arial, sans-serif; color: rgba(255, 255, 255, 0.5); text-align: center; list-style: none; cursor: pointer;
}
ul li.is-selected { background: #fbfbfb; color: rgba(0, 0, 255, 0.5);
}
Smooth Scroll - Script Codes JS Codes
'use strict';
document.querySelector('ul').addEventListener('click', function (e) { smoothScrollTo(selected(e.target, this).offsetTop, this);
});
function smoothScrollTo(destination, parent, time) { var scroll = init(); requestAnimationFrame(shouldScroll); function init() { var start = parent.scrollTop; var ticks = time || 30; var i = 0; var positionY = function positionY() { return (destination - start) * i / ticks + start; }; var isFinished = function isFinished() { return i++ >= ticks; }; return { positionY: positionY, isFinished: isFinished }; } function shouldScroll() { if (scroll.isFinished()) return; parent.scrollTop = scroll.positionY(); requestAnimationFrame(shouldScroll); }
}
function selected(elem, parent) { for (var i = 0; i < parent.children.length; i++) { parent.children[i].classList.remove('is-selected'); } elem.classList.add('is-selected'); return elem;
}
Developer | Lorenzo D'Ianni |
Username | lorenzodianni |
Uploaded | September 29, 2022 |
Rating | 3 |
Size | 3,561 Kb |
Views | 22,264 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Checkbox Style 2.0 - SCSS | 4,075 Kb |
Material Design - Switch | 3,282 Kb |
AngularJS template | 6,104 Kb |
SidebarJS | 3,666 Kb |
Ng-barcode | 2,888 Kb |
Cards experience | 10,660 Kb |
Off Canvas in SASS | 5,680 Kb |
Material Design - Animations | 9,001 Kb |
NgEasyModal | 4,159 Kb |
Ng-circle | 3,355 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Foundation 5 Menu - Accessibility | Xporter | 1,999 Kb |
Simple Login Form Template | Banunn | 3,571 Kb |
Rows with image hover effect | Amit-webdesigner | 12,875 Kb |
Layout 11 | Altynai | 1,690 Kb |
Scroll to view if element partially out of view port height | ChrisMaki | 2,104 Kb |
Dribbble Inspired Registration Form | Lancebush | 2,358 Kb |
LBCA - Mail canvas | Emnbdx | 3,856 Kb |
Fixed Scrolling Nav Bar | Philsinatra | 0 Kb |
Form Labels | Bartuc | 2,717 Kb |
Perspective Origin Demo | Agelber | 3,614 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!