It is used to scroll the texts which are presnt in the canvas elements
<h2 style="color:black"><i>Canvas scroll bar</i></h2>
<style>
html, body
{
width:100%;
height:100%;
margin:0;
overflow:hidden
}
#parent {
width:400px;
height:400px;
border:1px solid #000;
overflow:auto;
}
.canvas {
width:auto;
height:200%;
}
</style>
<div id="parent">
<canvas id="canvas" class="canvas" width="2500" height="3500"></canvas>
</div>
<script>
var canvas = document.getElementById("canvas");
var context = canvas.getContext('2d');
i = 10;
context.lineWidth = 1;
context.strokeStyle = 'pink';
for (; i < canvas.height; i += 100) {
context.moveTo(i, 0);
context.lineTo(0, i);
}
context.stroke();
</script>
scroll bar
using canvas HTML5style sheet
to the element canvas
, body
, html
, parent
elements of the canvas canvas
, context as assigned to the canvas element line width
as 1 color
as pink. for
condition to check the i value is lessthan the canvas height
it increments
with the value 100 , which moves to the move (i, 0)
, context.lineTo(0, i);
which moves from the (0,i);output
Views: 25491 | Post Order: 40