随笔 - 25  文章 - 0 评论 - 10 阅读 - 20101
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

-
复制代码
<script type="text/javascript">
var Browser=new Object();
 Browser.userAgent
=window.navigator.userAgent.toLowerCase();
 Browser.ie
=/msie/.test(Browser.userAgent);
 Browser.Moz
=/gecko/.test(Browser.userAgent);
var PhotoShow={
 url:
"",
 title:
"",
 alt:
"",
 objWidth:(window.innerWidth)
?window.innerWidth:(document.documentElement&&document.documentElement.clientWidth)?document.documentElement.clientWidth:document.documentElement.offsetWidth,//获取窗体的可视区域的宽;
 objHeight:(window.innerHeight)?window.innerHeight:(document.documentElement&&document.documentElement.clientHeight)?document.documentElement.clientHeight:document.documentElement.offsetHeight,//也可以加上document.documentElement.scrollHeight
 init:function(){ //初始化,创建一个层宽度和高度为可视区域宽高
  var creatediv=document.createElement("div");
      creatediv.id
="divscreen";
  
with(creatediv.style){
      width
=this.objWidth+"px";
      height
=this.objHeight+"px";
      backgroundColor
="#000";
      position
="absolute";
      left
="0px";
      top
="0px";
      zIndex
=80;
      filter
="alpha(opacity=20)";
      opacity
=0.2;
  }
  document.body.insertBefore(creatediv,document.body.childNodes[
0]);
 }, 
 PhotoClick:
function(){//调用后判断图片的加载情况
     this.init();
     
var img=new Image();
     
if(Browser.ie){ 
         img.onreadystatechange
=function(){
             
if(img.readyState=="complete"||img.readyState=="loaded"){
                   PhotoShow.PhotoCallBack(img);
             }
         }
     }
else if(Browser.Moz){
         img.onload
=function(){
             
if(img.complete==true){
                 PhotoShow.PhotoCallBack(img);
             }
         }
     }
     img.src
=this.url;     
 },
 
 PhotoCallBack:
function(obj){//再创建一个最上面的层
    var imgwidth=obj.width;
    
var imgheight=obj.height;
    
var Itop=(this.objHeight-imgheight)/2-15;
    var Ileft=(this.objWidth-imgwidth)/2;   
    var maindiv=document.createElement("div");
        maindiv.id
="maindiv";
        
with(maindiv.style){
             width
=imgwidth+"px";
             height
=imgheight+"px";
             position
="absolute";            
             left
=right=Ileft+"px";            
             top
=bottom=Itop+"px";
             backgroundColor
="skyblue";
             border
="1px solid #000";
             padding
="12px";
             paddingBottom
="20px";
             zIndex
=100;         
        }  
        maindiv.appendChild(obj);
        
var closediv=document.createElement("div");
            closediv.width
=imgwidth+20+"px";
            
with(closediv.style){
                textAlign
="center";
                background
="#fff";
                fontSize
="14px"    ;                            
            }
            
var Lhref=document.createElement("A");
                Lhref.href
="javascript:void(0)";                
                Lhref.appendChild(document.createTextNode(
"关 闭"));
                Lhref.onclick
=function(){
                    PhotoShow.PhotoRemove();
                }        
                closediv.appendChild(Lhref);
             
if(Browser.ie){                //由于ff与ie在加载对象方面出现了差异所以..
                 obj.insertAdjacentElement("afterEnd",closediv);
             }
else if(Browser.Moz){
               obj.parentNode.insertBefore(closediv,obj);
            }
        document.body.insertBefore(maindiv,document.body.childNodes[
0]);    
 } ,
 PhotoRemove:
function(){     //移除对象
      if(document.getElementById("maindiv")){
         document.body.removeChild(document.getElementById(
"maindiv"));
     }
     
if(document.getElementById("divscreen")){
         document.body.removeChild(document.getElementById(
"divscreen"));
     }     
return false;
 }
}

</script>
复制代码
<img src=http://www.xxx.com/1.jpg  onclick="PhotoShow.url=http://www.xxx.com/1.jpg ;PhotoShow.PhotoClick();" width="200" height="200"/>

-
在多个浏览器上测试过没出现什么异常
posted on   〤‵坠落者...  阅读(3136)  评论(1编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· AI 智能体引爆开源社区「GitHub 热点速览」
· Manus的开源复刻OpenManus初探
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示