Source code

Revision control

Copy as Markdown

Other Tools

- name: 2d.scrollPathIntoView.basic
desc: scrollPathIntoView() works
canvas_types: ['HtmlCanvas']
code: |
var div = document.createElement('div');
div.style.cssText = 'width: 200vw; height: 200vh';
document.body.appendChild(div);
canvas.style.cssText = 'position: absolute; top: 100px; left: 200px; border: none;';
window.scrollTo(0, 0);
ctx.beginPath();
ctx.rect(4, 8, 16, 32);
ctx.scrollPathIntoView();
var rect = canvas.getBoundingClientRect();
@assert Math.round(rect.top) === -8;
@assert Math.round(rect.left) === 200;
- name: 2d.scrollPathIntoView.verticalLR
desc: scrollPathIntoView() works in vertical-lr writing mode
canvas_types: ['HtmlCanvas']
code: |
document.documentElement.style.cssText = 'writing-mode: vertical-lr';
var div = document.createElement('div');
div.style.cssText = 'width: 200vw; height: 200vh';
document.body.appendChild(div);
canvas.style.cssText = 'position: absolute; top: 100px; left: 200px; border: none;';
window.scrollTo(0, 0);
ctx.beginPath();
ctx.rect(4, 8, 16, 32);
ctx.scrollPathIntoView();
var rect = canvas.getBoundingClientRect();
@assert Math.round(rect.top) === 100;
@assert Math.round(rect.left) === -4;
- name: 2d.scrollPathIntoView.verticalRL
desc: scrollPathIntoView() works in vertical-rl writing mode
canvas_types: ['HtmlCanvas']
code: |
document.documentElement.style.cssText = 'writing-mode: vertical-rl';
var div = document.createElement('div');
div.style.cssText = 'width: 200vw; height: 200vh';
document.body.appendChild(div);
canvas.style.cssText = 'position: absolute; top: 100px; right: 200px; border: none;';
window.scrollTo(0, 0);
ctx.beginPath();
ctx.rect(4, 8, 16, 32);
ctx.scrollPathIntoView();
var rect = canvas.getBoundingClientRect();
var viewportWidth = document.scrollingElement.clientWidth;
var canvasWidth = canvas.width;
@assert Math.round(rect.top) === 100;
@assert Math.round(rect.right) === viewportWidth + (canvasWidth - 4 - 16);
- name: 2d.scrollPathIntoView.path
desc: scrollPathIntoView() with path argument works
canvas_types: ['HtmlCanvas']
code: |
var div = document.createElement('div');
div.style.cssText = 'width: 200vw; height: 200vh';
document.body.appendChild(div);
canvas.style.cssText = 'position: absolute; top: 100px; left: 200px; border: none;';
window.scrollTo(0, 0);
var path = new Path2D();
path.rect(4, 8, 16, 32);
ctx.scrollPathIntoView(path);
var rect = canvas.getBoundingClientRect();
@assert Math.round(rect.top) === -8;
@assert Math.round(rect.left) === 200;