JavaScript实现动画打开半透明提示层的方法

 更新时间:2015年04月21日 12:27:20   作者:休闲生活文化  
这篇文章主要介绍了JavaScript实现动画打开半透明提示层的方法,涉及javascript操作DOM的相关技巧,非常具有实用价值,需要的朋友可以参考下

本文实例讲述了JavaScript实现动画打开半透明提示层的方法。分享给大家供大家参考。具体如下:

<!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=gb2312" />
<title>DOM半透明提示层</title>
<style type="text/css">
body,span,div,td{font-size:12px;line-height:1.5em;color:#849BCA;}
#bodyL{
float:left;
width:84px;
margin-right:2px;
}
a.od{
width:80px;
height:25px;
line-height:25px;
text-align:center;
font-weight:bold;
border: 2px solid #849BCA;
display:block;
color:#547BC9;
float:left;
text-decoration:none;
margin-top:2px;
}
a.od:link{
background:#EEF1F8;
}
a.od:visited{
background:#EEF1F8;
}
a.od:hover{
background:#EEE;
}
a.od:active{
background:#EEE;
}
#fd{
width:500px;
height:200px;
background:#EDF1F8;
border: 2px solid #849BCA;
margin-top:2px;
margin-left:2px;
float:left;
overflow:hidden;
position:absolute;
left:0px;
top:0px;
cursor:move;
float:left;
}
.content{
padding:10px;
}
</style>
</head>
<body>
<div id="bodyL">
<a href="#" class="od" onclick = "show('fd');return false;">
[打开层]
</a>
<a href="#" class="od" onclick = "closeed('fd');return false;">
[关闭层]
</a>
</div>
<div id="fd" style="display:none;filter:alpha(opacity=100);opacity:1;">
<div class="content">移动层</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,500)},10);
}
function openx(o,x){/*--打开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,200)},10);
}
}
function openy(o,y){/*--打开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){/*--打开y--*/
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){/*--打开x--*/
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><br/>
<div>https://www.jb51.net/</div>
</body>
</html>

希望本文所述对大家的javascript程序设计有所帮助。

相关文章

  • js实现淘宝固定侧边栏

    js实现淘宝固定侧边栏

    这篇文章主要为大家详细介绍了js实现淘宝固定侧边栏,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-07-07
  • 用chart.js添加动态背景图

    用chart.js添加动态背景图

    这篇文章主要为大家详细介绍了用chart.js添加动态背景图,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2022-06-06
  • myFocus slide3D v1.1.0 使用方法与下载

    myFocus slide3D v1.1.0 使用方法与下载

    myFocus slide3D v1.1.0 使用方法与下载,需要的朋友可以参考下。
    2011-01-01
  • js/jQuery简单实现选项卡功能

    js/jQuery简单实现选项卡功能

    本篇文章主要是对js/jQuery简单实现选项卡功能的示例代码进行了介绍,需要的朋友可以过来参考下,希望对大家有所帮助
    2014-01-01
  • 鼠标滚轮控制网页横向移动实现思路

    鼠标滚轮控制网页横向移动实现思路

    设置window的scrollLeft值,这里一定要是window不能是body否则滚动有问题,绑定事件mousewhell 也必须是在body上,感兴趣的各位可以了解下哈,希望可以帮助到你
    2013-03-03
  • 深入学习JS XML和Fetch请求

    深入学习JS XML和Fetch请求

    这篇文章主要介绍了深入学习JS XML和Fetch请求,文章通过围绕主题展开详细的内容介绍,具有一定的参考价值,需要的小伙伴可以参考一下
    2022-09-09
  • JavaScript 轻松搞定快捷留言功能 只需一行代码

    JavaScript 轻松搞定快捷留言功能 只需一行代码

    快捷留言功能,就是您现在看到在右侧浮动的那个小玩意,通过它可以直接提交留言并推荐,您想在博客里加上这个功能吗?
    2010-04-04
  • KnockoutJs快速入门教程

    KnockoutJs快速入门教程

    这篇文章主要为大家分享了KnockoutJs快速入门教程,了解KnockoutJs到底是什么?如何使用KnockoutJS中的data-bind语法来将模型数据绑定到DOM元素中,感兴趣的小伙伴们可以参考一下
    2016-05-05
  • 性能优化之代码优化页面加载速度

    性能优化之代码优化页面加载速度

    本文主要介绍了代码优化页面加载速度的方法。具有很好的参考价值,下面跟着小编一起来看下吧
    2017-03-03
  • 前端学习笔记style,currentStyle,getComputedStyle的用法与区别

    前端学习笔记style,currentStyle,getComputedStyle的用法与区别

    这篇文章主要介绍了前端学习笔记style,currentStyle,getComputedStyle的用法与区别,需要的朋友可以参考下
    2016-05-05

最新评论