- HTML Canvas - Home
- HTML Canvas - Introduction
- Environmental Setup
- HTML Canvas - First Application
- HTML Canvas - Drawing 2D Shapes
- HTML Canvas - Path Elements
- 2D Shapes Using Path Elements
- HTML Canvas - Colors
- HTML Canvas - Adding Styles
- HTML Canvas - Adding Text
- HTML Canvas - Adding Images
- HTML Canvas - Canvas Clock
- HTML Canvas - Transformations
- Composting and Clipping
- HTML Canvas - Basic Animations
- Advanced Animations
- HTML Canvas API Functions
- HTML Canvas - Element
- HTML Canvas - Rectangles
- HTML Canvas - Lines
- HTML Canvas - Paths
- HTML Canvas - Text
- HTML Canvas - Colors and Styles
- HTML Canvas - Images
- HTML Canvas - Shadows and Transformations
- HTML Canvas Useful Resources
- HTML Canvas - Quick Guide
- HTML Canvas - Useful Resources
- HTML Canvas - Discussion
HTML Canvas - scrollPathIntoView() Method
The HTML Canvas scrollPathIntoView() method takes the CanvasRenderingContext2D interface context object and scrolls the path given into view.
Syntax
Following is the syntax of HTML Canvas scrollPathIntoView() method −
CanvasRenderingContext2D.scrollPathIntoView(cur_path);
Parameters
Following is the list of parameters of this method −
| S.No | Parameter & Description |
|---|---|
| 1 |
cur_path
The path to which the method is to be applied. |
Return Value
When the following method is applied to the CanvasRenderingContext2D interface context object, the path of the object is made available in the view.
Example 1
The following example demonstrates how the HTML Canvas scrollPathIntoView() method is used inside the Canvas element.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Reference API</title>
<style>
body {
margin: 10px;
padding: 10px;
}
</style>
</head>
<body onload="Context();">
<canvas id="canvas" width="200" height="200" style="border: 1px solid black;"></canvas>
<script>
function Context() {
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
context.beginPath();
context.moveTo(100, 50);
context.lineTo(50, 100);
context.lineTo(150, 100);
context.lineTo(100, 50);
context.fillStyle = 'brown';
context.fill();
context.closePath();
context.strokeRect(30, 30, 150, 100);
context.scrollPathIntoView();
}
</script>
</body>
</html>
Output
The output returned by the above code on the webpage as −
Example 2
The following example demonstrates how the scrollPathIntoView() method hides the shape drawn inside the Canvas element when it has bigger boundaries than the original canvas element.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Reference API</title>
<style>
body {
margin: 10px;
padding: 10px;
}
</style>
</head>
<body>
<canvas id="canvas" width="300" height="200" style="border: 1px solid black;"></canvas>
<script>
var canvas = document.getElementById('canvas');
var context = canvas.getContext('2d');
context.beginPath();
// remove the below line to observe the difference
context.scrollPathIntoView();
context.strokeRect(30, 30, 350, 200);
</script>
</body>
</html>
Output
The output returned by the above code on the webpage as −