// Set of the variables used in the calculus
let windowSize = 200
let contentSize = 400
// Determine how large our track is
let trackSize = 500
// ISSO PODE VIRAR UMA FUNÇAO. OU UMA PROPRIEDADE COMPUTADA
// calculates the viewContentRatio
let windowContentRatio = windowSize / contentSize // SÓ É UTILIZADO PRA CALCULAR O TAMANHO DO GRIP :D
// Multiply the trackSize by the ratio to determine how large our grip will be
let gripSize = trackSize * windowContentRatio
// The minimal size of our grip
let minGripSize = 20
if (gripSize < minGripSize) gripSize = minGripSize
// The maximum size of our grip
let maxGripSize = trackSize
if (gripSize > maxGripSize) gripSize = maxGripSize
document.querySelector('.scrollGrip').style.height = gripSize + 'px'
// AREAS DOS SCROLLS
// Determina quanto a window pode scrollar
/*
* Determina quanto a window pode scrollar
* equivalente ao scrollableWidth e scrollableHeight
*/
let windowScrollAreaSize = contentSize - windowSize
// tamanho total da area que o grip pode ser scrollado.
let trackScrollAreaSize = trackSize - gripSize
/*
* Posição do window no track
* equivalente ao scrollTop e scrollLeft
*/
let windowPosition = 0
// posição do grip
let gripPositionOnTrack = 0
// VARIAVEIS PARA O MOUSE MOVE
let oldMousePosition = null
let newMousePosition = null
let mousePositionDelta = null
function handleMouseMove (e) {
newMousePosition = e.clientY
mousePositionDelta = newMousePosition - oldMousePosition
// calcula a nova posição do grip
let newGripPosition = gripPositionOnTrack + mousePositionDelta
// Limita a posição do grip aos limites da area de track
if (newGripPosition < 0) newGripPosition = 0
if (newGripPosition > trackScrollAreaSize) newGripPosition = trackScrollAreaSize
// Seta a posição do grip na variavel para ser reutilizado e depois aplica no DOM
gripPositionOnTrack = newGripPosition
document.querySelector('.scrollGrip').style.top = gripPositionOnTrack + 'px'
// calcula o ratio...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.