请帮助图像显示... [英] Help with image display please...

查看:85
本文介绍了请帮助图像显示...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的网络图库来交换我的图像
http:/ /dev.lenosphotography.com


转到家庭部分(应在底部打开图片栏 - 您可能需要

向下滚动 - 我还没有最终确定位置) - 当你点击

图像缩略图时,它会调用一个页面(使用此代码将引用传递给图像名称

。 swapfade代码basicall交换通过淡化一个图像为

另一个...所以我加载空白的jpg,其大小设置为真实图像W / H -

然后调用swapfade函数...


< script language =" javascript1.2" type =" text / javascript">


var iWidth = 0;

var iHeight = 0;


img1 = new Image();

img1.src =' '<%= Request.QueryString(" photo")%>'';


iHeight = img1.height;

iWidth = img1.width;


document.write("< img src =''images / photoblank.jpg''border ='' 1''id =''photo''

width =",iWidth," height =",iHeight,">");

// alert(document.documentElement.innerHTML);

swapfade(document.getElementById(''照片''),''<%= Requ est.QueryString(

" photo")%>'',''1','''');


< / script>


_________________________________________________-


99%的时间工作 - 但每一次所以图像经常会出现

宽度和高度= 0 - 我确信这是因为图像没有完全支付,所以在img1.height行之前加载了
我已经在

这个网上搜索了这个,并找到了我需要确保图像完整/加载的地方

测试它的高度和宽度 - 我尝试过的任何工作都没有...


感谢您的帮助!

I am trying to create a simple web gallery to swap my images at
http://dev.lenosphotography.com

Go to the family section (should open a image bar at bottom - you may have
to scroll down - I have not finalized placement) - when you click on the
image thumbnail it calls a page (passing the reference to the "image name"
with this code. The swapfade code basicall swaps via fading one image for
another.. so I load the blank jpg with the size set to the real images W/H -
then call the swapfade function...

<script language="javascript1.2" type="text/javascript">

var iWidth = 0;
var iHeight = 0;

img1 = new Image();
img1.src = ''<%=Request.QueryString( "photo" )%>'';

iHeight=img1.height;
iWidth=img1.width;

document.write ("<img src=''images/photoblank.jpg'' border=''1'' id=''photo''
width=", iWidth, " height=", iHeight, ">");
// alert(document.documentElement.innerHTML);
swapfade(document.getElementById(''photo''),''<%=Requ est.QueryString(
"photo" )%>'', ''1'', '''');

</script>

_________________________________________________-

This works 99% of the time - but every so often the image comes up with
width and height = 0 - I am sure that it is due to the image not being fully
loaded before the img1.height line is called.. I have scoured the net on
this and found where I need to make sure the image is complete/loaded before
testing for it''s height and width- nothing I have tried has worked yet...

Thanks for your help!

推荐答案

Hiya Doug


您是否尝试过onload事件处理程序?


您需要将img1.src =<%.....之后的所有内容移动到

单独的函数中,然后将img1.onload设置为此函数的名称。


这样的东西


- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -


< script language =" javascript1.2" type =" text / javascript">


var iWidth = 0;

var iHeight = 0;


img1 = new Image();

img1.src =''<%= Request.QueryString(" photo")%>'';

img1.onload = imgLoaded;


函数imgLoaded(anImg){// anImg自动设置....

iHeight = anImg.height;

iWidth = anImg.width;


document.write("< img src =''images / photoblank.jpg''border =''1' '

id =''photo''

width =",iWidth," height =",iHeight,">");

// alert(document.documentElement.innerHTML);

swapfade(document.getElementById(''photo''),''<%= Requ est.QueryString(

" photo")%>'','''','''');

}

< /脚本>


- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -


这有什么好处给你?

tihu

Hiya Doug

Have you tried the onload event handler?

You will need to move everything after img1.src = <%..... into a
separate function then set img1.onload to the name of this function.

Something like this

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

<script language="javascript1.2" type="text/javascript">

var iWidth = 0;
var iHeight = 0;

img1 = new Image();
img1.src = ''<%=Request.QueryString( "photo" )%>'';
img1.onload = imgLoaded;

function imgLoaded( anImg ) { //anImg is set automatically....
iHeight=anImg.height;
iWidth=anImg.width;

document.write ("<img src=''images/photoblank.jpg'' border=''1''
id=''photo''
width=", iWidth, " height=", iHeight, ">");
// alert(document.documentElement.innerHTML);
swapfade(document.getElementById(''photo''),''<%=Requ est.QueryString(
"photo" )%>'', ''1'', '''');
}
</script>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Is that any good to you?
tihu


我会试一试并报告回来......谢谢!

tihu < TI ******** @ gmail.com>在消息中写道

news:11 ********************** @ g47g2000cwa.googlegr oups.com ...
I''ll give it a try and report back...THANKS!
"tihu" <ti********@gmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...
Hiya Doug

您是否尝试过onload事件处理程序?

您需要在img1.src =<%.....之后移动所有内容单独的函数然后将img1.onload设置为此函数的名称。

这样的东西

- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -

< script language =" javascript1。 2英寸type =" text / javascript">

var iWidth = 0;
var iHeight = 0;

img1 = new Image();
img1.src =''<%= Request.QueryString(" photo")%>'';
img1.onload = imgLoaded;

函数imgLoaded(anImg){ //自动设置anImg ....
iHeight = anImg.height;
iWidth = anImg.width;

document.write("< img src =' 'images / photoblank.jpg''border =''1''
id =''photo''
width =",iWidth," height =",iHeight,"> ");
// alert(document.documentElement.innerHTML);
swapfade(document.getElementById(''photo''),''<%= Requ est.QueryString(
照片)%>'',''1','''');
}
< / script>

- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -

是对你有什么好处?
tihu
Hiya Doug

Have you tried the onload event handler?

You will need to move everything after img1.src = <%..... into a
separate function then set img1.onload to the name of this function.

Something like this

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

<script language="javascript1.2" type="text/javascript">

var iWidth = 0;
var iHeight = 0;

img1 = new Image();
img1.src = ''<%=Request.QueryString( "photo" )%>'';
img1.onload = imgLoaded;

function imgLoaded( anImg ) { //anImg is set automatically....
iHeight=anImg.height;
iWidth=anImg.width;

document.write ("<img src=''images/photoblank.jpg'' border=''1''
id=''photo''
width=", iWidth, " height=", iHeight, ">");
// alert(document.documentElement.innerHTML);
swapfade(document.getElementById(''photo''),''<%=Requ est.QueryString(
"photo" )%>'', ''1'', '''');
}
</script>

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

Is that any good to you?
tihu



Hiya。


抱歉,我在上面的回复中犯了一个错误。


imgLoaded函数没有得到图像副本,它收到一个

事件对象。


所以imgLoaded函数需要是


函数imgLoaded(事件){

iHeight = img1.height;

iWidth = img1.width;


祝你好运

Hiya.

Sorry I made a mistake in my above reply.

The imgLoaded function doesnt get a copy of the image, it receives an
event object.

So the imgLoaded function needs to be

function imgLoaded( event ) {
iHeight=img1.height;
iWidth=img1.width;

Good luck


这篇关于请帮助图像显示...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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