I've got a 5500 pxl wide panorama img (with usemap='#imagemap') on which I've overlain a canvas. These are parented inside a div.
Everything works as expected; the img view is restricted to the div, and can be scrolled. But the complete (wiiiide) canvas is visible in the browser window.
In addition, the canvas doesn't scroll with the div/img. I have to move it in an onscroll().
Edit: Here's a fiddle http://jsfiddle.net/91y2upam/1/ showing the canvas (outlined in green) escaping from the div.
Can a canvas be kept "inside" its parent div, with restricted view, and scrolled?
If so, how so?
The CSS:
#divPano {
width: 100%;
overflow: auto;
}
#cvsPano {
pointer-events: none; /* make the canvas transparent to the mouse - needed since canvas is position infront of image */
position: absolute;
}
and HTML:
<div name="divPano" id="divPano">
<canvas id='cvsPano'></canvas>
<img name='imgPano' id='imgPano' usemap='#mapPano' src='Pano/Pano0H500s.jpg' >
</div>
and the overlay JS (called from onload()):
function cvsInit(cvs, img) {
var x, y, w, h;
// get it's position and width+height
x = img.offsetLeft;
y = img.offsetTop;
w = img.width;
h = img.height;
// place cvsPano in front of the image
cvs.style.zIndex = 1;
cvs.parentNode.style.zIndex = 2; // <- this didn't work :-(
// position it over the image
cvs.style.left = x+'px';
cvs.style.top = y+'px';
// make same size as the image
cvs.setAttribute('width', w+'px');
cvs.setAttribute('height', h+'px');
// get it's context
hdc = cvs.getContext('2d');
// set the 'default' values for the colour/width of fill/stroke operations
hdc.strokeStyle = '#007700';
hdc.lineWidth = 1;
} // function cvsInit()