HTML5 Canvas Scrollbar

Developer
Size
2,863 Kb
Views
58,696

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 Previews

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();
});
HTML5 Canvas Scrollbar - Script Codes
HTML5 Canvas Scrollbar - Script Codes
Home Page Home
Developer Ash Blue
Username ashblue
Uploaded July 18, 2022
Rating 3
Size 2,863 Kb
Views 58,696
Do you need developer help for HTML5 Canvas Scrollbar?

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!

Ash Blue (ashblue) Script Codes
Create amazing SEO content with AI!

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!