图片显示自动适应大小处理

本文介绍了一种使用JavaScript实现的图片自适应方法,并提供了一个查看图片原始尺寸的功能。通过限制图片宽度并添加提示按钮,实现了良好的视觉效果及用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 
<HEAD>
  
<TITLE> New Document </TITLE>
  
<style type="text/css">
 .goNote 
{ background-color:#738B3F;width:128;
 border
:1px;font-size:12px;padding:5px;color:white;cursor:pointer; }
</style>
  
<SCRIPT LANGUAGE="JavaScript">
  
<!--
    
function autoResize(o)
    {
        
if (o.width>128
        { 
            o.width 
= 128;
            
if (o.parentNode.parentNode.childNodes.length == 1)
            {
                
var note = document.createElement("div");
                note.innerHTML 
= "<span class=/"goNote/" onclick=/"getSrcPic(this)/">查看原始图片</span>";
                o.parentNode.parentNode.appendChild(note);
            }
            
else
            {
                
try
                {
                    o.parentNode.parentNode.childNodes(
1).style.display = "block";
                }
                
catch (e) { }
            }
        }
    }

    
function getSrcPic(o)
    {
        
var t = o.parentNode.previousSibling.firstChild;
        
if (t.tagName.toLowerCase() == "img")
        {
            t.removeAttribute(
"width");
            t.removeAttribute(
"height");
            o.parentNode.style.display 
= "none"
            
//try { o.parentNode.removeNode(true) } catch (e) { o.parentNode.style.display = "none"; }
        }
    }
  
//-->
  </SCRIPT>
 
</HEAD>

 
<BODY>
 
<TABLE cellpadding="0" cellspacing="0" border="0">
 
<TR>
    
<TD><href="javascript:void(0)"><img id="myimg" src="http://img.pconline.com.cn/images/photoblog/4784529/20073/23/1174579895696_mthumb.jpg" onLoad='autoResize(this);' onmouseout="autoResize(this)" border="0" /></a></TD>
 
</TR>
 
</TABLE> 
 
</BODY>
</HTML>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值