设置Img1 = Img2 [英] Set Img1 = Img2

查看:93
本文介绍了设置Img1 = Img2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何加载图像然后将其分配给图片?


示例:

< Script>

ImgPre =新图像();

ImgPre.Src =" SomeImage.jpg"


//等到它加载.. 。


imgDisplay.image = imgPre.image


< / Script>


< ; img id =" imgDisplay" >


谢谢


Sid。

How can I load an image and then assign it to a picture ?

Example:
<Script>

ImgPre = New Image();
ImgPre.Src = "SomeImage.jpg"

// Wait till its loaded ...

imgDisplay.image = imgPre.image

</Script>

<img id="imgDisplay" >

Thanks

Sid.

推荐答案

不确定这是否是你想要的,但是 -


< img id =" imgDisplay" /<! - 请注意结尾''/ ''tag。

另外,最好在调用脚本之前存在img标记。 - >

< script type =" text / javascript">


//"脚本都是小写字母,你需要类型属性

ImgPre = new Image(); //''new''也是小型上限。

ImgPre.Src =" SomeImage.jpg"

ImgPre.onload = function(){

document.getElementById(''imgDisplay'')。setAttribute(''src'',ImgPre.src);

}

< / script> ;


是吗?

sid写道:
Not exactly sure if this is what you want, but -

<img id="imgDisplay"/ <!--please note the ending ''/'' tag.
Also, best that the img tag exist before the script is called. -->
<script type="text/javascript">

//"script is all small letters, and you need the "type" attribute
ImgPre = new Image(); //''new'' is small caps as well.
ImgPre.Src = "SomeImage.jpg"
ImgPre.onload=function(){
document.getElementById(''imgDisplay'').setAttribute (''src'', ImgPre.src);
}
</script>

Yeah?
sid wrote:

如何加载图像然后将它分配给图片?


示例:

<脚本>


ImgPre =新图片() ;

ImgPre.Src =" SomeImage.jpg"


//等到装满......


imgDisplay.image = imgPre.image


< / Script>


< img id =" imgDisplay" >


谢谢


希德。
How can I load an image and then assign it to a picture ?

Example:
<Script>

ImgPre = New Image();
ImgPre.Src = "SomeImage.jpg"

// Wait till its loaded ...

imgDisplay.image = imgPre.image

</Script>

<img id="imgDisplay" >

Thanks

Sid.


是的,但为什么''。src''属性而不是'.image''属性?

在我看来,你将第一张

图像的源路径指定为第二张路径。我试图让图像在后台加载

,然后当它加载时,将其图像移动到

秒。


谢谢


Sid。

Pi写道:
Yes, but why the ''.src'' property and not the ".image" property ?
It seems to me that you are assigning the source path of the first
image as the path of the second. I am trying to get the image to load
in the background and then when its loaded, move its image to the
second.

Thanks

Sid.
Pi wrote:

不确定这是不是是你想要的,但是 -


< img id =" imgDisplay" /<! - 请注意结尾的''/''标签。

另外,最好在调用脚本之前存在img标记。 - >

< script type =" text / javascript">


//"脚本都是小写字母,你需要类型属性

ImgPre = new Image(); //''new''也是小型上限。

ImgPre.Src =" SomeImage.jpg"

ImgPre.onload = function(){

document.getElementById(''imgDisplay'')。setAttribute(''src'',ImgPre.src);

}

< / script> ;


是吗?

sid写道:
Not exactly sure if this is what you want, but -

<img id="imgDisplay"/ <!--please note the ending ''/'' tag.
Also, best that the img tag exist before the script is called. -->
<script type="text/javascript">

//"script is all small letters, and you need the "type" attribute
ImgPre = new Image(); //''new'' is small caps as well.
ImgPre.Src = "SomeImage.jpg"
ImgPre.onload=function(){
document.getElementById(''imgDisplay'').setAttribute (''src'', ImgPre.src);
}
</script>

Yeah?
sid wrote:

如何加载图像然后将它分配给图片?


示例:

<脚本>


ImgPre =新图片() ;

ImgPre.Src =" SomeImage.jpg"


//等到装满......


imgDisplay.image = imgPre.image


< / Script>


< img id =" imgDisplay" >


谢谢


希德。
How can I load an image and then assign it to a picture ?

Example:
<Script>

ImgPre = New Image();
ImgPre.Src = "SomeImage.jpg"

// Wait till its loaded ...

imgDisplay.image = imgPre.image

</Script>

<img id="imgDisplay" >

Thanks

Sid.


Hrmm。我不认为Image对象有一个.image。属性。我理解自己的脚本是这样的 -


首先用变量ImgPre为''new''语句分配一些空格。

然后通过将源分配给

从中分配来获取图像的位置,即 - ''src''。请注意,一旦给出了src,

浏览器开始加载图像在后台。可以这么说,分配给它的内存为



现在,上传图片,执行以下操作 - 带元素

id =''imgDisplay'',并将其src指定为与ImgPre相同。现在,因为我已经加载了ImgPre.src指向的图像空间,所以它只是将它从内存中取出并将其从

浏览器内存,因此做你要求的,即 - 在背景中获取图像到

加载,然后当它加载时,将其图像移动到

秒。


我不是100%肯定自己,但我认为我是对的。我给它的脚本是否有效?


sid写道:
Hrmm. I dont think the Image object has an ".image" property. The way I
understand my own script is this -

First assign some space to a variable ImgPre with the ''new'' statement.
Then assign where to grab the image from by assigning the source to
pull it from, ie - ''src''. Mind you, as soon as the src is given, the
browser starts to load the image "in the background" so to speak, into
the memory allocated for it.
Now, onload of the image, perform the following - take the element with
id = ''imgDisplay'', and assign its src to the same as ImgPre. Now since
the image space that ImgPre.src points to is already loaded, it simply
takes it out of that memory and loads it onto the document from your
browser memory, hence doing what you asked for, ie - "get the image to
load in the background and then when its loaded, move its image to the
second."

I''m not 100% sure myself, but I think I''m right. Does the script work
as I gave it?

sid wrote:

是的,但为什么''。src''属性而不是'.image''属性?

在我看来,你将第一张

图像的源路径指定为第二张路径。我试图让图像在后台加载

,然后当它加载时,将其图像移动到

秒。


谢谢


Sid。


Pi写道:
Yes, but why the ''.src'' property and not the ".image" property ?
It seems to me that you are assigning the source path of the first
image as the path of the second. I am trying to get the image to load
in the background and then when its loaded, move its image to the
second.

Thanks

Sid.
Pi wrote:

Not确切地说这是否是你想要的,但是 -


< img id =" imgDisplay" /<! - 请注意结尾的''/''标签。

另外,最好在调用脚本之前存在img标记。 - >

< script type =" text / javascript">


//"脚本都是小写字母,你需要类型属性

ImgPre = new Image(); //''new''也是小型上限。

ImgPre.Src =" SomeImage.jpg"

ImgPre.onload = function(){

document.getElementById(''imgDisplay'')。setAttribute(''src'',ImgPre.src);

}

< / script> ;


是吗?

sid写道:
Not exactly sure if this is what you want, but -

<img id="imgDisplay"/ <!--please note the ending ''/'' tag.
Also, best that the img tag exist before the script is called. -->
<script type="text/javascript">

//"script is all small letters, and you need the "type" attribute
ImgPre = new Image(); //''new'' is small caps as well.
ImgPre.Src = "SomeImage.jpg"
ImgPre.onload=function(){
document.getElementById(''imgDisplay'').setAttribute (''src'', ImgPre.src);
}
</script>

Yeah?
sid wrote:

如何加载图像然后将它分配给图片?

>

示例:

< Script>

>

ImgPre =新图像();

ImgPre.Src =" SomeImage.jpg"

>

/ /等到装满......

>

imgDisplay.image = imgPre.image

>

< / Script>

>

< img id =" imgDisplay" >

>

谢谢

>

希德。
How can I load an image and then assign it to a picture ?
>
Example:
<Script>
>
ImgPre = New Image();
ImgPre.Src = "SomeImage.jpg"
>
// Wait till its loaded ...
>
imgDisplay.image = imgPre.image
>
</Script>
>
<img id="imgDisplay" >
>
Thanks
>
Sid.


这篇关于设置Img1 = Img2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆