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 相关文章推荐
正则表达式中特殊符号及正则表达式的几种方法总结(replace,test,search)
Nov 26 Javascript
根据表格中的某一列进行排序的javascript代码
Nov 29 Javascript
javascript中处理时间戳为日期格式的方法
Jan 02 Javascript
js使用DOM操作实现简单留言板的方法
Apr 10 Javascript
JavaScript 判断一个对象{}是否为空对象的简单方法
Oct 09 Javascript
JQuery学习总结【二】
Dec 01 Javascript
jQuery 选择符详细介绍及整理
Dec 02 Javascript
jquery实现提示语淡入效果
May 05 jQuery
深入理解Node中的buffer模块
Jun 03 Javascript
jQuery选择器之表单元素选择器详解
Sep 19 jQuery
微信小程序实现语音识别转文字功能及遇到的坑
Aug 02 Javascript
使用jQuery实现掷骰子游戏
Oct 24 jQuery
教你使用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 获取百度的热词数据的代码
2012/02/18 PHP
php中session过期时间设置及session回收机制介绍
2014/05/05 PHP
整理php防注入和XSS攻击通用过滤
2015/09/13 PHP
php实现当前页面点击下载文件的简单方法
2016/09/22 PHP
PHP+Redis 消息队列 实现高并发下注册人数统计的实例
2018/01/29 PHP
详解php协程知识点
2018/09/21 PHP
PHP中常见的密码处理方式和建议总结
2018/10/14 PHP
jquery 1.3.2 IE8中的一点点的小问题解决方法
2009/07/10 Javascript
javascript encodeURI和encodeURIComponent的比较
2010/04/03 Javascript
jquery实现居中弹出层代码
2010/08/25 Javascript
jquery.validate的使用说明介绍
2013/11/12 Javascript
Bootstrap基本插件学习笔记之按钮(21)
2016/12/08 Javascript
js中document.referrer实现移动端返回上一页
2017/02/22 Javascript
jQuery实现的鼠标滚轮控制图片缩放功能实例
2017/10/14 jQuery
Vue.js实现分页查询功能
2020/11/15 Javascript
一次记住JavaScript的6个正则表达式方法
2018/02/22 Javascript
vue 注册组件的使用详解
2018/05/05 Javascript
javascript匿名函数中的'return function()'作用
2018/10/15 Javascript
Layui数据表格跳转到指定页的实现方法
2019/09/05 Javascript
vue-父子组件和ref实例详解
2019/11/10 Javascript
[05:26]2014DOTA2西雅图国际邀请赛 iG战队巡礼
2014/07/07 DOTA
Python中防止sql注入的方法详解
2017/02/25 Python
numpy中的meshgrid函数的使用
2019/07/31 Python
使用Pycharm(Python工具)新建项目及创建Python文件的教程
2020/04/26 Python
jupyter notebook指定启动目录的方法
2021/03/02 Python
HTML5地理定位实例
2014/10/15 HTML / CSS
HTML5录音实践总结(Preact)
2020/05/07 HTML / CSS
酒店公关部经理岗位职责
2013/11/24 职场文书
警示教育活动总结
2014/05/05 职场文书
改作风抓落实促发展心得体会
2014/09/10 职场文书
庆元旦演讲稿
2014/09/15 职场文书
干部作风整顿个人剖析材料
2014/10/06 职场文书
作文评语集锦
2014/12/25 职场文书
幸福终点站观后感
2015/06/04 职场文书
企业法人代表证明书
2015/06/18 职场文书
java多态注意项小结
2021/10/16 Java/Android