Skip to content

Instantly share code, notes, and snippets.

@igorbenic
Created November 27, 2024 13:49
Show Gist options
  • Select an option

  • Save igorbenic/8d3f250803fae6ae7096cdf4c182943d to your computer and use it in GitHub Desktop.

Select an option

Save igorbenic/8d3f250803fae6ae7096cdf4c182943d to your computer and use it in GitHub Desktop.
Horizontal Scroll Native
function nativeHorizontalScroll( id ) {
var elID = id;
var element = document.getElementById( id );
var scrolling = false;
var initialX = 0;
function getParent( node, id ) {
if ( node.id === id ) {
return node;
}
if ( ! node.parentElement ) {
return null;
}
return getParent( node.parentElement, id );
}
function scroll( initial, changed ) {
var diff = (-1.25) * ( changed - initial );
var currentScroll = element.scrollLeft;
var maxScroll = element.scrollWidth - element.clientWidth;
if ( currentScroll === 0 && diff < 0 ) {
return;
}
currentScroll = currentScroll + diff;
if ( currentScroll < 0 ) {
currentScroll = 0;
}
if ( currentScroll > maxScroll ) {
currentScroll = maxScroll;
}
initialX = changed;
element.scroll( currentScroll, element.scrollTop );
}
function disableSelect(event) {
event.preventDefault();
}
addEventListener("mousemove", (event) => {
if ( ! scrolling ) {
return;
}
window.addEventListener('selectstart', disableSelect);
scroll( initialX, event.clientX );
});
addEventListener("mouseup", (event) => {
if ( scrolling ) {
window.removeEventListener('selectstart', disableSelect);
scrolling = false;
}
})
addEventListener("mousedown", (event) => {
var target = event.target || event.originalTarget;
if ( ! getParent( target, elID ) ) {
return;
}
scrolling = true;
initialX = event.clientX;
});
}
@huria1057-jpg

Copy link
Copy Markdown

It’s interesting how code snippets like this highlight the importance of clean structure and efficiency when building or modifying functionality.
Even small tweaks in logic can significantly improve usability and overall experience for users interacting with a system.AD786 Free Game is a reliable real earning app for users in Pakistan who want more than just casual gaming, bringing together engaging gameplay with a focus on simplicity, transparency, and a localized experience for users.

@edwardseves18889-sketch

Copy link
Copy Markdown

Nice and practical snippet. The scroll.js approach looks useful for handling scroll-related behavior, and it’s a good example of keeping front-end functionality focused and easy to understand. New users pick 777cxgame to try a secure UPI deposit system alongside a first deposit bonus. Weekly leaderboards rank top players and hand out extra cash prizes.

@wren-fr

wren-fr commented Sep 13, 2026

Copy link
Copy Markdown

É interessante como até pequenas alterações no código podem melhorar a estrutura, a eficiência, a usabilidade e a experiência geral do usuário. Um somador de horas soma turnos que ultrapassam a meia noite sem exigir ajustes manuais adicionais. Trabalhadores de plantão noturno se beneficiam diretamente do recurso.

@johnmiller926

Copy link
Copy Markdown

This code provides a straightforward way to add native horizontal scrolling with mouse dragging. The boundary checks also help keep the scroll position within the available range. It is a useful approach for improving navigation in wide interfaces, and 88FD fits naturally as an example of another interactive digital experience. The function is also easy to follow and adapt.

@davidjames288

Copy link
Copy Markdown

Code snippets make it easier for developers to share reusable code, explain programming concepts, and simplify technical documentation. Clear formatting and readable typography are essential for presenting code-related content effectively. A Font Generator can help developers create stylish headings, attractive labels, and unique text designs for coding blogs, tutorials, and developer websites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment