Slimscroll
How do I make an slimscroll?
What is a slimscroll? How do you make a slimscroll? This script and codes were developed by Gyula Szathmary on 02 November 2022, Wednesday.
Slimscroll - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Slimscroll</title>
</head>
<body> <script src="js/index.js"></script>
</body>
</html>
Slimscroll - Script Codes JS Codes
var slimScroll = function(C, payload){ var i = {}, w = "wrapper",s = "scrollBar",S = "scrollBarContainer",a = "",m = "",l="data-slimscroll", // properties oT = "offsetTop",sT = "scrollTop",pE = "parentElement",pes= "previousElementSibling", iH = "innerHTML",cT = "currentTarget",sK = "scroll-k",U = "%",d = ".", // IE8 properties // (Dev note: remove below variables from all over the code to exclude IE8 compatibility) pN = "parentNode",pS = "previousSibling",sE = "srcElement", assignValues = function(k){ var q = i.E; i.h = i[S].offsetHeight; i.sH = i[w].scrollHeight; i.sP = (i.h/i.sH) * 100; // i.sbh is scroll bar height in pixels without pixel unit. i.sbh = i.sP * i.h/100; // Manually set the height of the scrollbar (in percentage) // if user hasn't provided the fixed scroll height value if(!q.sH) i.sP1 = i.sbh < q.mH? (q.mH/i.h * 100): i.sP; else i.sP1 = q.sH/i.h * 100; i.rP1 = 100 - i.sP1; i.x = (i.sH - i.h) * ((i.sP1 - i.sP)/(100 - i.sP)); i.sH1 = Math.abs((i.x / (i.rP1)) + (i.sH/100)); i[s].style.height = i.sP1 + U; i.reposition = getReposition(i[s], i.h); }, // Start of private functions setAttr = function(e, p, v){ e.setAttribute(p,v); }, getAttr = function(e, p){ if(!e) return; return e.getAttribute(p); }, addClass = function(e, c){ if(c.length) e.className = c; }, cE = function(c, h, p){ var d = document.createElement('div'); addClass(d, c); d[iH] = h; p.appendChild(d); return d; }, setScroll = function(e){ var e = e || event,el = e.target || event[sE], p = el[pE] || el[pN]; var q = i.E; if(!i || p === i[S]) return; var eY = e.pageY || event.clientY, top = ((eY - getTop(i[w][pE] || i[w][pN]))/i.h * 100) - i.sP1/2; if(top > i.rP1) top = i.rP1; else if(top < 0) top = 0; i[s].style.top = top + U; i[w][sT] = top * i.sH1; addClass(i[S], q.S + q.a); }, beginScroll = function(e){ // removing selected text // Link: http://stackoverflow.com/a/3171348 var sel = window.getSelection ? window.getSelection() : document.selection; if (sel) { if (sel.removeAllRanges) sel.removeAllRanges(); else if (sel.empty) sel.empty(); } var e = e || event, el = e[cT] || e[sE]; addEvent('mousemove', document, moveScroll); addEvent('mouseup', document, endScroll); i[oT] = getTop(i[w]); i.firstY = e.pageY || event.clientY; if(!i.reposition) i.reposition = getReposition(i[s], i.h); // Disable text selection while dragging the scrollbar return false; }, getReposition = function(i, h){ var x = parseInt(i.style.top.replace(U,""),10) * h/100; return x?x:0; }, moveScroll = function(e){ var e = e || event, q = i.E, eY = e.pageY || e.clientY, top = (i.reposition + eY - i.firstY)/i.h * 100; if(i.rP1 < top) top = i.rP1; if(!i.previousTop) i.previousTop = top + 1; var blnThreshold = top >= 0 && i.firstY > i[oT]; if((i.previousTop > top && blnThreshold) || (blnThreshold && (i[w][sT] + i.h !== i.sH))){ i[s].style.top = top + U; i.previousTop = top; i[w][sT] = top * i.sH1; } addClass(i[S], q.S); }, endScroll = function(e){ var e = e || event,q = i.E; removeEvent('mousemove', document); removeEvent('mouseup', document); i.reposition = 0; addClass(i[S], q.S + q.a); }, doScroll = function(e){ var e = e || event; if(!i) return; var q = i.E; addClass(i[S], q.S); i[s].style.top = i[w][sT]/i.sH1 + U; addClass(i[S], q.S + q.a); }, addEvent = function(e, el, func){ el['on' + e] = func; // el.addEventListener(e, func, false); }, removeEvent = function(e, el){ el['on' + e] = null; // el.removeEventListener(e, func, false); }, addCSSRule = function(S, s, r, i) { if(S.insertRule) S.insertRule(s + "{" + r + "}", i); else if(S.addRule) S.addRule(s, r, i); }, getTop = function(el){ var t = document.documentElement[sT]; return el.getBoundingClientRect().top + (t?t:document.body[sT]); }, insertCss = function(){ if(window.slimScroll.inserted){ return; } // Inserting css rules // Link: http://davidwalsh.name/add-rules-stylesheets var slim = "["+l+"]", imp = " !important", pA = "position:absolute"+imp, // classes w = pA+";overflow:auto"+imp+";left:0px;top:0px"+imp+";right:0px;bottom:0px"+imp+";padding-right:8px"+imp+";", S = pA+";top:0px"+imp+";bottom:0px"+imp+";right:0px;left:auto;width:5px;cursor:pointer"+imp+";padding-right:0px"+imp+";", s = pA+";background-color:#999;top:0px;left:0px;right:0px;", //creating a sheet style = document.createElement('style'), scrollBar = "[data-scrollbar]"; try{ // WebKit hack :( style.appendChild(document.createTextNode("")); }catch(ex){} var head = document.head || document.getElementsByTagName('head')[0]; // adding above css to the sheet head.insertBefore(style, (head.hasChildNodes()) ? head.childNodes[0] : null); var sheet = style.sheet; if(sheet){ addCSSRule(sheet, slim+">div", w, 0); addCSSRule(sheet, slim+">div+div", S, 0); addCSSRule(sheet, scrollBar, s, 0); } else{ style.styleSheet.cssText = slim+">div{"+w+"}"+slim+">div+div"+"{"+S+"}"+slim+">div+div>div{"+s+"}"; } window.slimScroll.inserted = true; }, // Initial function init = function(){ C.removeAttribute(l); //reset if(C.offsetHeight < C.scrollHeight){ setAttr(C, l, '1'); insertCss(); var h = C[iH], q = i.E = {}; // setting user defined classes payload = payload || {}; q.w = payload.wrapperClass || ""; q.s = payload.scrollBarClass || ""; q.S = payload.scrollBarContainerClass || ""; q.a = payload.scrollBarContainerSpecialClass ? " " + payload.scrollBarContainerSpecialClass : ""; q.mH = payload.scrollBarMinHeight || 25; q.sH = payload.scrollBarFixedHeight; // could be undefined C[iH] = ""; i[w] = cE(q.w, h, C); i[S] = cE(q.S + q.a, "", C); i[s] = cE(q.s, "", i[S]); setAttr(i[s], 'data-scrollbar', '1'); assignValues(); var scrollBarWidth = i[w].offsetWidth - i[w].clientWidth; // Stretching the inner container so that the default scrollbar is completely invisible if(Math.abs(scrollBarWidth) < 5){ // Seems scrollbar isn't taking width. // So we can safely assume that the scrollbar looks beautiful // Hence, lets not modify the default scrollbar // Mostly, the scrollbar looks beautiful on Mac OSX // Removing our custom scroll component C.removeChild(i[S]); // returning to avoid further process return false; } else{ i[w].style.right = -scrollBarWidth + "px"; } if(payload.keepFocus){ setAttr(i[w], 'tabindex', '-1'); i[w].focus(); } // Attaching mouse events addEvent('mousedown', i[s], beginScroll); addEvent('click', i[S], setScroll); // For scroll addEvent('scroll', i[w], doScroll); // addEvent('selectstart', i[S], function(){return;}); } }(); return { resetValues: assignValues }
};
Developer | Gyula Szathmary |
Username | gyusza |
Uploaded | November 02, 2022 |
Rating | 3 |
Size | 4,090 Kb |
Views | 46,552 |
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 |
Get 23 thumbnail | 2,148 Kb |
Navigate to coordinates from link in google maps | 1,805 Kb |
Rotating Outrageous Predictions 2016 | 14,585 Kb |
A Pen by Gyula Szathmary | 5,177 Kb |
Saxo Tools Collection | 1,993 Kb |
Monthly Product Update v2 | 5,799 Kb |
Simple Tabs | 5,071 Kb |
Sitemap generator for Sharepoint | 2,518 Kb |
Webinar v2 | 2,868 Kb |
Replace text string jQuery | 1,793 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 |
Clock with full screen background | Owebboy | 2,415 Kb |
Learning FlexBox | Alex_rodrigues | 2,821 Kb |
Algorithm practice | Abensur | 5,620 Kb |
JavaScript constructors | Simboonlong | 2,415 Kb |
CSS Patterns | Alyda | 3,953 Kb |
Opening Reveal Modal On Document Ready | Winghouchan | 1,787 Kb |
Twinkling Stars | Ripley6811 | 2,750 Kb |
Canvas Background Effect | Sonick | 3,513 Kb |
A simple log in form made with css | Mayurelbhar | 2,160 Kb |
Experiment - SCSS SVG Background Image with Variables | See8ch | 3,270 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!