2011-06-01 64 views
-1

我有一个div overflow=hidden;就像我在这里添加的那个。我在里面有一些图像,一些在可见的div区域,一些在它之外(意思是如果div宽度是300,图像剩下500,所以你看不到图像)。我用一个JavaScript函数改变了图像的位置(全部彼此)。 如何在div区域加载图像(意思是:图像的左上角是div宽度和高度)?如何在div区加载图片?

而且我用一个通用拖动移动图像,就像这里描述的一个,在这里描述的Generic Drag

<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> 
+1

尝试改写你的问题,这是很难理解 – Ibu 2011-06-01 05:55:29

+0

@Ibu更新,这部分是很难理解 – hamze 2011-06-01 06:04:27

+0

谢谢你,现在它使更多的意义 – Ibu 2011-06-01 06:08:43

回答

0

相对的位置添加到您的div,并且可以跟踪图像位置(上/左)和当图像处于正常范围时src属性添加到您的IMG属性的位置。

我建议使用jQuery因为它会给你更多的功能和更多的浏览器支持的drag and drop

例子:

<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')); 

这应该工作。

0

试试这个,

<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> 
+0

的问题是只在可见范围内加载图像 – Ibu 2011-06-01 06:37:13