如何解决如何在div区域加载图像?
| 我有一个divoverflow=hidden;
,就像我在此处添加的那个一样。我有一些图像,一些在可见的div区域中,而有些不在其中(这意味着如果div宽度为300,则图像为500,因此您看不到该图像)。我使用JavaScript函数更改图像位置(彼此之间)。如何仅在到达div区域时加载图像(即:图像的顶部和左侧位于div的宽度和高度中)?
我使用通用拖动来移动图像,就像通用拖动中所述的那样。
<div id=\"mydiv\" style=\"overflow=hidden; width: 300px; height: 300px; border: 1px solid #f00;\">
<img id=\"Img1\" border=\"0\"
style=\"z-index: 10; position: absolute; visibility: visible; left: 481px; top: 347px; height: 15px; width: 16px;\"
src=\"house1.gif\">
<img id=\"Img2\" border=\"0\"
style=\"z-index: 10; position: absolute; visibility: visible; left: 200px; top: 200px; height: 15px; width: 16px;\"
src=\"house1.gif\">
<img id=\"Img3\" border=\"0\"
style=\"z-index: 10; position: absolute; visibility: visible; left: -50px; top: -50px; height: 15px; width: 16px;\"
src=\"house1.gif\">
<img id=\"Img4\" border=\"0\"
style=\"z-index: 10; position: absolute; visibility: visible; left: 481px; top: 50px; height: 15px; width: 16px;\"
src=\"house1.gif\">
<img id=\"Img5\" border=\"0\"
style=\"z-index: 10; position: absolute; visibility: visible; left: 50px; top: 60px; height: 15px; width: 16px;\"
src=\"house1.gif\">
</div>
解决方法
添加相对于
div
的位置,您可以跟踪图像位置的位置(顶部/左侧),当图像在范围内时,将add3ѭ属性添加到img属性。
我建议使用jQuery,因为它将为您提供更多功能和更多浏览器对拖放的支持。
例:
<img id=\"Img1\" border=\"0\" style=\"z-index: 10; position: absolute; visibility: visible;
left: 481px; top: 347px; height: 15px; width: 16px;\" deffered=\"house1.gif\">
JavaScript代码:
// If image is in range.
var image = $(\'Img1\');
image.attr(\'src\',image.attr(\'deffered\'));
这应该工作。
, 尝试这个,
<div id=\"mydiv\" style=\"overflow:hidden; min-height:300px; min-width:300px; border: 1px solid #f00;\">
<img id=\"Img1\" border=\"0\" style=\"z-index: 10;
left: 481px; top: 347px; height: 400px; width: 400px;\" src=\"...\">
</div>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。