简体   繁体   English

如何在html java页面中固定静态图像上的标记

[英]how to pin a marker on static image in html java page

I am displaying one static image using html/jsp/javascript. 我正在使用html / jsp / javascript显示一个静态图像。 I am trying to pin a marker on the static image by using absolute and relative tags. 我试图通过使用绝对和相对标签在静态图像上固定标记。

<div style="position: relative; left: 0; top: 0;">
<img src="a.jpg" style="position: relative; top: 0; left: 0;"/>
<img src="b.jpg" style="position: absolute; top: 25px; left: 25px;"/>
</div>

The problem is when i zoom the image, marker remains on the screen at same 25px, 25px. 问题是当我缩放图像时,标记保持在屏幕上相同的25px,25px。 How can i lock the marker on the image so that even after zooming or moving the image scroll bar, marker should move automatically along with the image. 如何锁定图像上的标记,以便即使在缩放或移动图像滚动条后,标记也应随图像一起自动移动。

with above code, it appears marker is locked on the screen, not on the static image. 使用上面的代码,它会出现标记锁定在屏幕上,而不是静态图像上。

If you're only scrolling or zooming the image itself, the marker is unaffected and remains in place. 如果您只是滚动或缩放图像本身,则标记不受影响并保持不变。 Instead, try changing the entire div element containing both images. 相反,尝试更改包含两个图像的整个div元素。

For example, if you did something like this: 例如,如果你做了这样的事情:

<div style="position: relative; overflow: auto; width: 100; height: 100;">
  <!-- both images here -->
</div>

The containing div will gain scroll bars which move both images, keeping them aligned. 包含div将获得滚动条,移动两个图像,使它们保持对齐。 (This will only take effect if the div is smaller than your main image, since there's no need for scroll bars otherwise.) (这仅在div小于主图像时生效,否则不需要滚动条。)

As for zooming / scaling: it depends on how you're doing it. 至于缩放/缩放:这取决于你是如何做的。 If you're using the browser's zoom function, it should work no matter what. 如果您正在使用浏览器的缩放功能,它无论如何都应该有效。 If you're applying some CSS to the image, applying that CSS to the div instead should do the trick. 如果你将一些CSS应用于图像,那么将该CSS应用于div应该可以解决问题。 If you're resizing the image using javascript, you'll probably need to do some calculations to determine the marker's new position. 如果您使用javascript调整图像大小,则可能需要进行一些计算以确定标记的新位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM