由於急需要一些簡單的JS效果,剛好去對岸借了一個範例來改有需要的就拿去吧! 整篇貼到HTML即可執行 如果要分檔案再把CSS和JS分離吧


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf8" />
<title>Div+IFram 應用</title>
<style type="text/css">
#bodyR{
float:right;
width:80px;
margin-right:0px;
}
a.od{
width:120px;
height:20px;
line-height:20px;
text-align:center;
border: 1px solid #DDD;
display:block;
color:#333;
float:right;
text-decoration:none;
}
a.od:link{
background:#EEE;
}
a.od:visited{
background:#EEE;
}
a.od:hover{
background:#FFF;
}
a.od:active{
background:#EEE;
}


#fd{
background:#FFF;
border: 1px solid #DDD;
margin-top:1px;
margin-right:1px;
float:right;
overflow:hidden;
position:inherit;
cursor:move;
float:right;


}
.content{
padding:0px;
}



a.od2{
width:20px;
height:20px;
line-height:20px;
text-align:center;
border: 1px solid #DDD;
display:block;
color:#000;
float:right;
text-decoration:none;
}
a.od2:link{
background:#FFF;
}
a.od2:visited{
background:#EEF1F8;
}
a.od2:hover{
background:#EEE;
}
a.od2:active{
background:#EEE;
}



</style>
</head>
<body>
<div id="bodyR">
<a href="#" onclick = "show('fd');return false;">
展開DiV  +Ifram 移動應用
</a>

</div>
<div id="fd" style="display:none;filter:alpha(opacity=100);opacity:1;">
<div>
<a href="#" onclick = "closeed('fd');return false;">X</a>
<iframe src="http://www.google.com" id="frameid" frameborder="0"  height="600" scrolling="no" width="300"></iframe>

</div>
</div>

<script type="text/javascript">
var prox;
var proy;
var proxc;
var proyc;
function show(id){
clearInterval(prox);
clearInterval(proy);
clearInterval(proxc);
clearInterval(proyc);
var o = document.getElementById(id);
o.style.display = "block";
o.style.width = "1px";
o.style.height = "1px";
prox = setInterval(function(){openx(o,300)},10);
}
function openx(o,x){
var cx = parseInt(o.style.width);
if(cx < x)
{
o.style.width = (cx + Math.ceil((x-cx)/5)) +"px";
}
else
{
clearInterval(prox);
proy = setInterval(function(){openy(o,300)},10);
}
}
function openy(o,y){
var cy = parseInt(o.style.height);
if(cy < y)
{
o.style.height = (cy + Math.ceil((y-cy)/5)) +"px";
}
else
{
clearInterval(proy);
}
}
function closeed(id){
clearInterval(prox);
clearInterval(proy);
clearInterval(proxc);
clearInterval(proyc);
var o = document.getElementById(id);
if(o.style.display == "block")
{
proyc = setInterval(function(){closey(o)},10);
}
}
function closey(o){
var cy = parseInt(o.style.height);
if(cy > 0)
{
o.style.height = (cy - Math.ceil(cy/5)) +"px";
}
else
{
clearInterval(proyc);
proxc = setInterval(function(){closex(o)},10);
}
}
function closex(o){
var cx = parseInt(o.style.width);
if(cx > 0)
{
o.style.width = (cx - Math.ceil(cx/5)) +"px";
}
else
{
clearInterval(proxc);
o.style.display = "none";
}
}



var od = document.getElementById("fd");
var dx,dy,mx,my,mouseD;
var odrag;
var isIE = document.all ? true : false;
document.onmousedown = function(e){
var e = e ? e : event;
if(e.button == (document.all ? 1 : 0))
{
mouseD = true;
}
}
document.onmouseup = function(){
mouseD = false;
odrag = "";
if(isIE)
{
od.releaseCapture();
od.filters.alpha.opacity = 100;
}
else
{
window.releaseEvents(od.MOUSEMOVE);
od.style.opacity = 1;
}
}


//function readyMove(e){
od.onmousedown = function(e){
odrag = this;
var e = e ? e : event;
if(e.button == (document.all ? 1 : 0))
{
mx = e.clientX;
my = e.clientY;
od.style.left = od.offsetLeft + "px";
od.style.top = od.offsetTop + "px";
if(isIE)
{
od.setCapture();
od.filters.alpha.opacity = 50;
}
else
{
window.captureEvents(Event.MOUSEMOVE);
od.style.opacity = 0.5;
}

//alert(mx);
//alert(my);

}
}
document.onmousemove = function(e){
var e = e ? e : event;

//alert(mrx);
//alert(e.button);
if(mouseD==true && odrag)
{
var mrx = e.clientX - mx;
var mry = e.clientY - my;
od.style.left = parseInt(od.style.left) +mrx + "px";
od.style.top = parseInt(od.style.top) + mry + "px";
mx = e.clientX;
my = e.clientY;

}
}
</script>
</body>
</html>


創作者介紹
創作者 andyyu0920 的頭像
andyyu0920

ANdyYoU_蹤雁_數位記錄本

andyyu0920 發表在 痞客邦 留言(0) 人氣()