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 相关文章推荐
jQuery checkbox全选/取消全选实现代码
Nov 14 Javascript
下拉菜单点击实现连接跳转功能的js代码
May 19 Javascript
JavaScript验证电子邮箱的函数
Aug 22 Javascript
js实现进度条的方法
Feb 13 Javascript
JavaScript基础知识之方法汇总结
Jan 24 Javascript
Vue.js教程之计算属性
Nov 11 Javascript
jQuery实现弹出窗口弹出div层的实例代码
Jan 09 Javascript
ES6新特性之变量和字符串用法示例
Apr 01 Javascript
JS小球抛物线轨迹运动的两种实现方法详解
Dec 20 Javascript
JavaScript实现多叉树的递归遍历和非递归遍历算法操作示例
Feb 08 Javascript
vue中子组件向父组件传递数据的实例代码(实现加减功能)
Apr 20 Javascript
详解Vue CLI 3.0脚手架如何mock数据
Nov 23 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+mysql留言本源码
2009/11/11 PHP
PHP中文件上传的一个问题
2010/09/04 PHP
PDO::rollBack讲解
2019/01/29 PHP
laravel 关联关系遍历数组的例子
2019/10/10 PHP
Laravel框架集合用法实例浅析
2020/05/14 PHP
php的单例模式及应用场景详解
2021/02/27 PHP
JavaScript常用对象的方法和属性小结
2012/01/24 Javascript
javascript获取xml节点的最大值(实现代码)
2013/12/11 Javascript
javascript感应鼠标图片透明度显示的方法
2015/02/24 Javascript
javascript数据结构之二叉搜索树实现方法
2015/11/25 Javascript
讲解JavaScript的Backbone.js框架的MVC结构设计理念
2016/02/14 Javascript
移动端H5开发 Turn.js实现很棒的翻书效果
2016/06/20 Javascript
js遍历map javaScript遍历map的简单实现
2016/08/26 Javascript
Angularjs2不同组件间的通信实例代码
2017/05/06 Javascript
vue升级之路之vue-router的使用教程
2018/08/14 Javascript
java和js实现的洗牌小程序
2019/09/30 Javascript
VUE注册全局组件和局部组件过程解析
2019/10/10 Javascript
JS Generator 函数的含义与用法实例总结
2020/04/08 Javascript
Vue axios 跨域请求无法带上cookie的解决
2020/09/08 Javascript
python中的五种异常处理机制介绍
2014/09/02 Python
Python3实现从指定路径查找文件的方法
2015/05/22 Python
在python里面运用多继承方法详解
2019/07/01 Python
python使用 zip 同时迭代多个序列示例
2019/07/06 Python
python移位运算的实现
2019/07/15 Python
pytorch 实现cross entropy损失函数计算方式
2020/01/02 Python
CSS3媒体查询Media Queries基础学习教程
2016/02/29 HTML / CSS
捷克时尚网上商店:OTTO
2018/03/15 全球购物
季度思想汇报
2014/01/01 职场文书
十佳青年个人事迹材料
2014/01/28 职场文书
个人先进事迹总结
2015/02/26 职场文书
中学图书馆工作总结
2015/08/11 职场文书
演讲稿之开卷有益
2019/08/07 职场文书
js不常见操作运算符总结
2021/11/20 Javascript
抖音动画片,皮皮虾,《治愈系》动画在用这首REMIX作为背景音乐,Anak ,The last world with you完整版
2022/03/16 杂记
TV动画《八十龟酱观察日记》第四季宣传PV公布
2022/04/06 日漫
vue配置型表格基于el-table拓展之table-plus组件
2022/04/12 Vue.js