HTML5 Canvas Scrollbar
How do I make an html5 canvas scrollbar?
Editable HTML5 Canvas scrollbar that can be toggled vertically or horizontally. Handles overflowing input and always lines up perfectly.. What is a html5 canvas scrollbar? How do you make a html5 canvas scrollbar? This script and codes were developed by Ash Blue on 18 July 2022, Monday.
HTML5 Canvas Scrollbar - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>HTML5 Canvas Scrollbar</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */ h1 { font-size: 20px; margin: 5px 5px 10px;
}
input[type="number"], li { display: block; margin-bottom: 10px;
}
form { margin: 5px;
}
canvas { padding: 20px;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <h1>Canvas Scrollbar Test</h1>
<form> <ul> <li> <input type="radio" name="direction" id="vertical" value="vertical" checked /> <label for="vertical">Vertical</label> <input type="radio" name="direction" id="horizontal" value="horizontal" /> <label for="horizontal">Horizontal</label> </li> <li> <label for="width">Width</label> <input type="number" id="width" value="20" /> </li> <li> <label for="height">Height</label> <input id="height" type="number" value="200" /> </li> <li> <label for="scrollbar">Scrollbar Size</label> <input id="scrollbar" type="number" value="10" /> </li> <li> <label for="max">Max Value</label> <input id="max" type="number" value="100" /> </li> <li> <label for="val">Value</label> <input id="val" type="number" value="20" /> </li> <li> <input id="submit" type="submit" /> </li> </ul>
</form>
<canvas id="canvas" width="500" height="500"><canvas> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
HTML5 Canvas Scrollbar - Script Codes CSS Codes
h1 { font-size: 20px; margin: 5px 5px 10px;
}
input[type="number"], li { display: block; margin-bottom: 10px;
}
form { margin: 5px;
}
canvas { padding: 20px;
}
HTML5 Canvas Scrollbar - Script Codes JS Codes
var canvas = document.getElementById('canvas'), ctx = canvas.getContext('2d');
function drawScrollbar () { var width = parseInt($('#width').val()), height = parseInt($('#height').val()), scrollbarSize = parseInt($('#scrollbar').val()), max = parseInt($('#max').val()), val = Math.min(Math.max(parseInt(parseInt($('#val').val())), 0), max), direction = $('input[name="direction"]:checked').val(); // Draw the background ctx.fillStyle = '#000'; ctx.clearRect(0, 0, canvas.width, canvas.height); ctx.fillRect(0, 0, width, height); console.log(width); // Draw the scrollbar ctx.fillStyle = '#777'; if (direction === 'vertical') { var scrollbarPosition = ((height - scrollbarSize) / max) * val; ctx.fillRect(0, scrollbarPosition, width, scrollbarSize); } else { var scrollbarPosition = ((width - scrollbarSize) / max) * val; ctx.fillRect(scrollbarPosition, 0, scrollbarSize, height); }
}
drawScrollbar();
$('#submit').click(function (e) { e.preventDefault(); drawScrollbar();
});
Developer | Ash Blue |
Username | ashblue |
Uploaded | July 18, 2022 |
Rating | 3 |
Size | 2,863 Kb |
Views | 58,696 |
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 |
Flow Chart Prototype | 4,149 Kb |
Fancy Image Zoom | 1,502 Kb |
JavaScript Anagram Algorithm Explanation | 1,897 Kb |
Pure CSS Responsive Modal | 1,161 Kb |
HTML5 Canvas Text Wrap Test | 3,076 Kb |
JavaScript Anagram Generator Alpha | 5,260 Kb |
Loader Example | 3,637 Kb |
CSS Zoom Icon | 1,553 Kb |
CSS Sprite Animation | 3,732 Kb |
Responsive Gallery Grid Layout | 2,071 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 |
Opening Reveal Modal On Document Ready | Winghouchan | 1,787 Kb |
CSS Grid Overlay | Cliffpyles | 3,090 Kb |
About Mazano | Kiti | 2,585 Kb |
SVG email test v2.0 | M_J_Robbins | 2,090 Kb |
Menu | Vivi_Lai | 1,210 Kb |
Ipad Mini Showcase | Hornebom | 10,479 Kb |
Print element on a page | Mrs_snow | 2,081 Kb |
Lecture 1 | Law | 0 Kb |
Reviews and Ratings Star | Zbnmstry | 1,591 Kb |
Coming Soon | MariamMassadeh | 1,680 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!