javascript - How to scale so that container also grows and takes up space -
so have container want scale , down (zoom in , out) have expanded/shrunk form take space rather overlapping other stuff.
update
there image there absolute divs placed in coordinates, must retain relative positions when sizing , down (hence why i'm using scale).
var b = document.getelementbyid("outer"); var scale = 1; function increase() { scale += 0.1 b.style.transform = `scale(${scale})`; } function decrease() { scale -= 0.1 b.style.transform = `scale(${scale})`; } #outer { overflow-x: auto position: relative; transform-origin: left top; } .pointer { width: 20px; height: 20px; background-color: orange; position: absolute; } #a1 { top: 50px; left: 150px; } #a2 { top: 150px; left: 50px; } #a3 { top: 250px; left: 550px; } <div> <button onclick="increase()">increase</button> <button onclick="decrease()">decrease</button> </div> <div id=outer> <img src="http://via.placeholder.com/600x350" /> <div id="a1" class='pointer'> </div> <div id="a2" class='pointer'> </div> <div id="a3" class='pointer'> </div> </div> <div> please don't cover me </div> would rather not have third party libraries (beside jquery) may consider.
css3 scale transitions work that. unfortunately, scaling would overlap other elements takes contents of container out of flow creating new stacking context (essentially putting contents positioned relative container) - see relevant doc description:
if property has value different none, stacking context created.
source: mdn
see demo below scaling elements brute force:
var b, scale = 1, offset, pointers; window.onload = function() { b = document.getelementbyid("outer"); offset = b.getboundingclientrect(); pointers = array.prototype.map.call(b.queryselectorall('.pointer'), function(e) { return { el: e, offset: e.getboundingclientrect() } }); } function increase() { scale += 0.1; scaleit(); } function decrease() { scale -= 0.1; scaleit(); } function scaleit() { b.style.width = scale * offset.width + 'px'; b.style.height = scale * offset.height + 'px'; array.prototype.foreach.call(pointers, function(e) { e.el.style.width = scale * e.offset.width + 'px'; e.el.style.height = scale * e.offset.height + 'px'; e.el.style.top = scale * e.offset.top + 'px'; e.el.style.left = scale * e.offset.left + 'px'; }); } #outer { /*overflow-x: auto;*/ position: relative; transform-origin: left top; } .pointer { width: 20px; height: 20px; background-color: orange; position: absolute; } #outer > img { height: 100%; } #a1 { top: 50px; left: 150px; } #a2 { top: 150px; left: 50px; } #a3 { top: 250px; left: 550px; } <div> <button onclick="increase()">increase</button> <button onclick="decrease()">decrease</button> </div> <div id=outer> <img src="http://via.placeholder.com/600x350" /> <div id="a1" class='pointer'> </div> <div id="a2" class='pointer'> </div> <div id="a3" class='pointer'> </div> </div> <div> please don't cover me </div>
Comments
Post a Comment