JS简单实现动画弹出层效果


Posted in Javascript onMay 05, 2015

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>
<title>动画弹出层</title>
<style>
.list{
position:relative;;
background:#eee;
border:1px #ccc solid;
margin:10px;
height:30px;
width:100px;
cursor :pointer ;
}
.listShow{
position:relative;
background:#eff;
border:1px #ddd solid;
margin:10px;
height:30px;
width:100px;
cursor :pointer ;
}
.comment{
position:absolute;
left:0;
display:none;
position:absolute;
border:1px #ccc solid;
background:#fee;
width:200px;
height:200px;
overflow:hidden;
z-index:100;
}
</style>
</head>
<body>
<div class="" id="show">
0
</div>
<div class="list" id="list1">1
<div class="comment" id="comment1">内容显示111<br/>
</div>
<div class="list" id="list2">2
<div class="comment" id="comment2">内容显示222</div>
</div>
<div class="list" id="list3">3
<div class="comment" id="comment3">内容显示333</div>
</div>
</body>
</html>
<script>
var zindex=0;
function $id(id){
return document.getElementById(id);
}
var Bind = function(object,fun){
var args = Array.prototype.slice.call(arguments).slice(2);
return function(){
return fun.apply(object,args);
}
}
function addEventHandler(oTarget, sEventType, fnHandler){ 
if(oTarget.addEventListener){oTarget.addEventListener(sEventType, fnHandler, false);}
else if(oTarget.attachEvent){oTarget.attachEvent('on' + sEventType, fnHandler);}
else{oTarget['on' + sEventType] = fnHandler;}
}
var Shower=function(){
this.list=null;
this.comment=null;
this.moveLeft=80; 
this.moveTop=20;
this.height=150;
this.width=250;
this.time=800;
this.init=function(lisObj,comObj){
this.list=lisObj;
this.comment=comObj;
var _this=this;
this._fnMove=Bind(this,this.move);
(function(){
var obj=_this;
addEventHandler(obj.list,"click",obj._fnMove);
})();
};
this.move=function(){
var _this=this;
var w=0; 
var h=0; 
var height=0; //弹出div的高
var width=0; //弹出div的宽
var t=0;
var startTime = new Date().getTime();//开始执行的时间
if(!_this.comment.style.display||_this.comment.style.display=="none"){
_this.comment.style.display="block";
_this.comment.style.height=0+"px";
_this.comment.style.width=0+"px";
_this.list.style.zIndex=++zindex;
_this.list.className="listShow";
var comment=_this.comment.innerHTML; 
_this.comment.innerHTML=""; //去掉显示内容
var timer=setInterval(function(){
var newTime = new Date().getTime();
var timestamp = newTime - startTime;
_this.comment.style.left=Math.ceil(w)+"px";
_this.comment.style.top=Math.ceil(h)+"px";
_this.comment.style.height=height+"px";
_this.comment.style.width=width+"px";
t++;
var change=(Math.pow((timestamp/_this.time-1), 3) +1); //根据运行时间得到基础变化量
w=_this.moveLeft*change;
h=_this.moveTop*change;
height=_this.height*change;
width=_this.width*change;
$id("show").innerHTML=w;
if(w>_this.moveLeft){
clearInterval(timer);
_this.comment.style.left=_this.moveLeft+"px";

_this.comment.style.top=_this.moveTop+"px"; _this.comment.style.height=_this.height+"px";

_this.comment.style.width=_this.width+"px";
_this.comment.innerHTML=comment; //回复显示内容
}
},1,_this.comment);
}else{
_this.hidden();
}
}
this.hidden=function(){
var _this=this;
var flag=1;
var hiddenTimer=setInterval(function(){
if(flag==1){
_this.comment.style.height=parseInt(_this.comment.style.height)-10+"px";
}else{ _this.comment.style.width=parseInt(_this.comment.style.width)-15+"px";
_this.comment.style.left=parseInt(_this.comment.style.left)+5+"px";
}
if(flag==1 && parseInt(_this.comment.style.height)<10){
flag=-flag;
}
if(parseInt(_this.comment.style.width)<20){
clearInterval(hiddenTimer);
_this.comment.style.left="0px";
_this.comment.style.top="0px";
_this.comment.style.height="0px";
_this.comment.style.width="0px";
_this.comment.style.display="none";
if(_this.list.style.zIndex==zindex){
zindex--;
};
_this.list.style.zIndex=0;
_this.list.className="list";
}
},1)
}
}
window.onload=function(){
//建立各个菜单对象
var shower1=new Shower();
shower1.init($id("list1"),$id("comment1"));
var shower2=new Shower();
shower2.init($id("list2"),$id("comment2"));
var shower3=new Shower();
shower3.init($id("list3"),$id("comment3"));
}
</script>

以上所述就是本文的全部内容了,希望大家能够喜欢。

Javascript 相关文章推荐
JavaScript高级程序设计 读书笔记之十 本地对象Date日期
Feb 27 Javascript
javascript实现焦点滚动图效果 具体方法
Jun 24 Javascript
按下回车键指向下一个位置的一个函数代码
Mar 10 Javascript
利用Keydown事件阻止用户输入实现代码
Mar 11 Javascript
微信小程序之页面跳转和参数传递的实现
Sep 29 Javascript
详解利用Angular实现多团队模块化SPA开发框架
Nov 27 Javascript
JavaScript实现的简单Tab点击切换功能示例
Jul 06 Javascript
微信小程序提取公用函数到util.js及使用方法示例
Jan 10 Javascript
mpvue小程序循环动画开启暂停的实现方法
May 15 Javascript
构建大型 Vue.js 项目的10条建议(小结)
Nov 14 Javascript
原生JS实现相邻月份日历
Oct 13 Javascript
js前端对于大量数据的展示方式及处理方法
Dec 02 Javascript
教你使用javascript简单写一个页面模板引擎
May 05 #Javascript
关于延迟加载JavaScript
May 05 #Javascript
Javascript闭包(Closure)详解
May 05 #Javascript
javascript实现仿IE顶部的可关闭警告条
May 05 #Javascript
JS实现点击按钮后框架内载入不同网页的方法
May 05 #Javascript
JS实现随机乱撞彩色圆球特效的方法
May 05 #Javascript
jquery实现图片随机排列的方法
May 04 #Javascript
You might like
PHP信号量基本用法实例详解
2016/02/12 PHP
PHP 等比例缩放图片详解及实例代码
2016/09/18 PHP
Yii框架where查询用法实例分析
2019/10/22 PHP
jQuery Ajax 全解析
2009/02/08 Javascript
javascript 模拟点击广告
2010/01/02 Javascript
Extjs TriggerField在弹出窗口显示不出问题的解决方法
2010/01/08 Javascript
几个有趣的Javascript Hack
2010/07/24 Javascript
brook javascript框架介绍
2011/10/10 Javascript
javascript 基础篇4 window对象,DOM
2012/03/14 Javascript
Js表格万条数据瞬间加载实现代码
2014/02/20 Javascript
JavaScript数据结构之链表的实现
2017/03/19 Javascript
vue组件 $children,$refs,$parent的使用详解
2017/07/31 Javascript
微信小程序swiper组件用法实例分析【附源码下载】
2017/12/07 Javascript
JavaScript原生实现观察者模式的示例
2017/12/15 Javascript
Vue 使用beforeEach实现登录状态检查功能
2019/10/31 Javascript
js中!和!!的区别与用法
2020/05/09 Javascript
Django自定义分页效果
2017/06/27 Python
详解Python map函数及Python map()函数的用法
2017/11/16 Python
利用python和ffmpeg 批量将其他图片转换为.yuv格式的方法
2019/01/08 Python
python3+opencv 使用灰度直方图来判断图片的亮暗操作
2020/06/02 Python
解决keras GAN训练是loss不发生变化,accuracy一直为0.5的问题
2020/07/02 Python
Selenium之模拟登录铁路12306的示例代码
2020/07/31 Python
HTML5等待加载动画效果
2017/07/27 HTML / CSS
购买瑞典当代设计的腕表和太阳眼镜:TRIWA
2016/10/30 全球购物
亿阳信通股份有限公司C#笔试题
2016/12/06 面试题
介绍一下Ruby中的对象,属性和方法
2012/07/11 面试题
技术学校毕业生求职信分享
2013/12/02 职场文书
高中校园广播稿
2014/01/11 职场文书
小学毕业家长寄语
2014/01/19 职场文书
消防先进事迹材料
2014/02/10 职场文书
领导干部作风建设总结
2014/10/23 职场文书
小学生光盘行动倡议书
2015/04/28 职场文书
六一儿童节园长致辞
2015/07/31 职场文书
python数字转对应中文的方法总结
2021/08/02 Python
JavaScript文档对象模型DOM
2021/11/20 Javascript
Windows server 2022创建创建林、域树、子域的步骤
2022/06/25 Servers