การเปิดดูรูปภาพแบบ popup และรูปภาพค่อยๆ ขยายขึ้นมา

วันนี้จะเอา Script ที่ใช้เวลาคลิกดูรูปเล็กให้เปิดเป็นรูปใหญ่ให้ popup และค่อยๆ ขยายขึ้นมานะครับ

1. สร้างไฟล์ demo.html เพื่อใช้ในการทดสอบ Script นะครับ แล้ว copy code ด้านล่างนี้ เอาไว้ที่ tag <body>...</body> นะครับ

<script language=javascript type=text/javascript>
<!--
var winheight=100
var winwidth=100
var cat=null

step=1;

function catswindows(name,width,height,title)
{

if (!document.all)
{
if (!document.layers)
{
paramstp="height="+height+",width="+width+",top=10"+
",left=10,scrollbars=no,location=no"+
",directories=no,status=no,menubar=no,toolbar=no,resizable=no"
cat=window.open("","cat",paramstp);
oldstr="<html><title>"+title+"</title><body background="+name+">"+"</b"+"ody></h"+"tml>";
cat.document.write(oldstr);
if (cat.focus){cat.focus();}
return;
}
else
{
LeftPosition=(screen.width)?(screen.width-width)/2:100;
TopPosition=(screen.height)?(screen.height-height)/2:100;
paramstp="height="+height+",width="+width+",top="+TopPosition+
",left="+LeftPosition+",scrollbars=no,location=no"+
",directories=no,status=no,menubar=no,toolbar=no,resizable=no"
cat=window.open("","cat",paramstp);
loadpos=height/2-40
string="<html><title>"+title+"</title><body bgcolor=black>
<div id=loadintxt style=&#39;position:absolute;top:"+loadpos+"px&#39;></div>"
string1=&#39;<s&#39;+&#39;cript>var animColorIndex=0;colorArray=["#FFFFFF","#CCCCCC","#999999",
"#666666","#333333","#000000","#333333","#666666","#999999","#CCCCCC"];&#39;
string2=&#39;function textLooping(){if(animColorIndex==10)animColorIndex=0;document.loadintxt.document.open();&#39;
string3=&#39;document.loadintxt.document.write("<center><font size=4 face=Comic Sans MS color="+colorArray[animColorIndex]+">Loading...</font></center>");document.loadintxt.document.close();&#39;
string4=&#39;animColorIndex++;};animInterval=setInterval("textLooping()",200);</s&#39;+&#39;cript>&#39;
string5=&#39;<s&#39;+&#39;cript language="jav&#39;+&#39;ascript1.2">&#39;
string6="function init(){document.catpic.visibility=&#39;show&#39;;clearInterval(animInterval);document.loadintxt.visibility=&#39;hide&#39;;};"
string7="</s"+"cript>"
string8="<div id=catpic style=&#39;position:absolute;left:0px;top:0px;visibility:hidden&#39;>"
string9="<img src=&#39;"+name+"&#39; width="+width+" height="+height+" border=0 onload=&#39;init()&#39;></div></b"+"ody></h"+"tml>";
cat.document.writeln(string);
cat.document.writeln(string1);
cat.document.writeln(string2);
cat.document.writeln(string3);
cat.document.writeln(string4);
cat.document.writeln(string5);
cat.document.writeln(string6);
cat.document.writeln(string7);
cat.document.writeln(string8);
cat.document.writeln(string9);
if(cat.focus){cat.focus();}
return;
}
}
LeftPosition=(screen.width)?(screen.width-width)/2:100;
TopPosition=(screen.height)?(screen.height-height)/2:100;
paramstp="height="+winheight+",width="+winwidth+",top="+TopPosition+
",left="+LeftPosition+",scrollbars=no,location=no"+
",directories=no,status=no,menubar=no,toolbar=no,resizable=no"
cat=window.open("","cat",paramstp);
string="<html><title>"+title+"</title><body topmargin=0 leftmargin=0 bgcolor=black>"
string1="<div id=loadintxt style=&#39;position:absolute;width:100%;top:45%;text-align:center;visibility:visible;font-family:
Comic Sans MS;font-size:16px; font-weight:bold&#39;>Loading...</div>"
string2="<div id=errtxt style=&#39;position:absolute;width:100%;top:45%;text-align:center;visibility:visible;font-family:
Comic Sans MS;font-size:16px;color:red;font-weight:bold;visibility:hidden&#39;>ERROR!!! Please try again</div>"
string3=&#39;<s&#39;+&#39;cript>&#39;+&#39;var animColorIndex=0;&#39;+
&#39;colorArray=["#FFFFFF","#CCCCCC","#999999","#666666","#333333","#000000","#333333","#666666"
,"#999999","#CCCCCC"];&#39;+&#39;function textLooping(){if(animColorIndex==10)animColorIndex=0;&#39;+
&#39;loadintxt.style.color=colorArray[animColorIndex];&#39;+
&#39;animColorIndex++;}animInterval=setInterval("textLooping()",200);&#39;
string4=&#39;function erroccur(){clearInterval(animInterval);&#39;+
"loadintxt.style.visibility=&#39;hidden&#39;;"+
"errtxt.style.visibility=&#39;visible&#39;;}"+&#39;</s&#39;+&#39;cript>&#39;
string5=&#39;<s&#39;+&#39;cript language="jav&#39;+&#39;ascript1.2">&#39;+
&#39;function init(){clearInterval(animInterval);&#39;+
"loadintxt.style.visibility=&#39;hidden&#39;;"+
&#39;fltr.filters.item(0).Apply();fltr.filters.item(0).Play();&#39;+
&#39;fltr.style.visibility="visible";}&#39;+&#39;</s&#39;+&#39;cript>&#39;;
string6=&#39;[img]&#39;+name+&#39;[/img]&#39;+
&#39;</b&#39;+&#39;ody></h&#39;+&#39;tml>&#39;;
cat.document.writeln(string);
cat.document.writeln(string1);
cat.document.writeln(string2);
cat.document.writeln(string3);
cat.document.writeln(string4);
cat.document.writeln(string5);
cat.document.writeln(string6);

x = y = step
while (x | y)
{
cat.resizeBy (x, y)
if (cat.document.body.clientWidth >= width) x = 0
if (cat.document.body.clientHeight >= height) y = 0
}
if(cat.focus){cat.focus();}
}

function CloseCatWin()
{if(cat!=null && cat.open)cat.close()}

window.onfocus=CloseCatWin;

//-->
</SCRIPT>

2. หลังจากนั้นเรามาสร้าง Link เพื่อให้ popup รูปภาพใหญ่ก็เป็นอันเสร็จเีรีัยบร้อยครับ ตามตัวอย่างด้านล่างครับ

[img]ชื่อรูปภาพขนาดใหญ่[/img]

คลิกดูตัวอย่าง