Image within an Image using HTML, CSS and JavaScript -
i created regular image in html. then, dynamically via javascript, added image within initial image. however, having issue if user zoom in or out, internal image not stay in same place. , possible user zoom in case, anytime, , need internal image not move. not have fancy, , trying sorts of ways work, if have way uses html , css, add code, because have tried many different avenues , changed html around multiple times. however, if code, in depth, glad supply you. appreciated, or if need more clarification, can well, in advance.
here example of code adds image image, , has issue explained above:
$(document).ready(function() { $('#myimgid').click(function(e) { var offx = event.clientx; var offy = event.clienty; margin = 20; if (offx > margin) offx -= margin; if (offy > margin) offy -= margin; var signhereimage = document.createelement("img"); signhereimage.setattribute('src', 'imageinserted.jpg'); signhereimage.setattribute('class', 'overlays'); signhereimage.style.left = offx + "px"; signhereimage.style.top = offy + "px"; document.body.appendchild(signhereimage); }); }); <form id="form1" runat="server"> <div> <img src="page3.jpg" alt="pdf image" id="myimgid" /> </div> </form> this part is, know doing incorrectly, not know certain, again in advance.
i use background-image property achieve this. can place image in div, give div background image, , position image relative div. here's working example:
div { position: relative; height: 500px; background-image: url(https://images.unsplash.com/photo-1413781892741-08a142b23dfe?dpr=2&auto=format&fit=crop&w=1500&h=1000&q=80&cs=tinysrgb&crop=&bg=); background-size: cover; } img { position: absolute; margin: auto; top: 0; bottom: 0; right: 0; left: 0; width: 200px; } <div> <img alt="img" src="https://images.unsplash.com/photo-1483086431886-3590a88317fe?dpr=2&auto=format&fit=crop&w=1500&h=2247&q=80&cs=tinysrgb&crop=&bg=" /> </div>
Comments
Post a Comment