JS实现响应鼠标点击动画渐变弹出层效果代码


Posted in Javascript onMarch 25, 2016

本文实例讲述了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=utf-8" />
<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">三水点靠木<br/>
</div>
<div class="list" id="list2">2
 <div class="comment" id="comment2">新浪搜狐</div>
</div>
<div class="list" id="list3">3
 <div class="comment" id="comment3">网页特效</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 相关文章推荐
jquery 模拟雅虎首页的点击对话框效果
Apr 11 Javascript
JQUERY1.6 使用方法四 检测浏览器
Nov 23 Javascript
JavaScript中prototype为对象添加属性的误区介绍
Oct 15 Javascript
jQuery网页版打砖块小游戏源码分享
Aug 20 Javascript
jquery ztree实现树的搜索功能
Feb 25 Javascript
【经验总结】编写JavaScript代码时应遵循的14条规律
Jun 20 Javascript
jQuery源码解读之extend()与工具方法、实例方法详解
Mar 30 jQuery
jQuery选取所有复选框被选中的值并用Ajax异步提交数据的实例
Aug 04 jQuery
node.js基于fs模块对系统文件及目录进行读写操作的方法详解
Nov 10 Javascript
使用JavaScript破解web
Sep 28 Javascript
Angular+ionic实现折叠展开效果的示例代码
Jul 29 Javascript
JavaScript实现动态生成表格
Aug 02 Javascript
JS+CSS实现鼠标经过弹出一个DIV框完整实例(带缓冲动画渐变效果)
Mar 25 #Javascript
JS+CSS实现的漂亮渐变背景特效代码(6个渐变效果)
Mar 25 #Javascript
详解Javascript继承的实现
Mar 25 #Javascript
JavaScript实现弹出DIV层同时页面背景渐变成半透明效果
Mar 25 #Javascript
JavaScript修改作用域外变量的方法
Mar 25 #Javascript
JavaScript 2048 游戏实例代码(简单易懂)
Mar 25 #Javascript
JavaScript入门系列之知识点总结
Mar 24 #Javascript
You might like
php获取文件大小的方法
2014/02/26 PHP
PHP中iconv函数知识汇总
2015/07/02 PHP
PDO::setAttribute讲解
2019/01/29 PHP
在js中使用&quot;with&quot;语句中跨frame的变量引用问题
2007/03/08 Javascript
在IE中调用javascript打开Excel的代码(downmoon原作)
2007/04/02 Javascript
深入理解JavaScript系列(12) 变量对象(Variable Object)
2012/01/16 Javascript
JavaScript中提前声明变量或函数例子
2014/11/12 Javascript
基于JavaScript实现单选框下拉菜单添加文件效果
2016/06/26 Javascript
js基础之DOM中document对象的常用属性方法详解
2016/10/28 Javascript
详解nodejs 文本操作模块-fs模块(三)
2016/12/22 NodeJs
Vue.js学习之计算属性
2017/01/22 Javascript
javascript基础知识之html5轮播图实例讲解(44)
2017/02/17 Javascript
JS和canvas实现俄罗斯方块
2017/03/14 Javascript
微信小程序中的canvas 文字断行和省略号显示功能的处理方法
2018/11/14 Javascript
详解ES6 export default 和 import语句中的解构赋值
2019/05/28 Javascript
layer.confirm点击第一个按钮关闭弹出框的方法
2019/09/09 Javascript
uni-app使用微信小程序云函数的步骤示例
2020/05/22 Javascript
Python中MYSQLdb出现乱码的解决方法
2014/10/11 Python
python 实时遍历日志文件
2016/04/12 Python
Tensorflow实现卷积神经网络用于人脸关键点识别
2018/03/05 Python
python 2.7.13 安装配置方法图文教程
2018/09/18 Python
对Pandas DataFrame缺失值的查找与填充示例讲解
2018/11/06 Python
对django layer弹窗组件的使用详解
2019/08/31 Python
flask框架自定义过滤器示例【markdown文件读取和展示功能】
2019/11/08 Python
Python numpy数组转置与轴变换
2019/11/15 Python
接口自动化多层嵌套json数据处理代码实例
2020/11/20 Python
CSS3 实现发光边框特效
2020/11/11 HTML / CSS
Ted Baker英国官网:男士和女士服装及配件
2017/03/13 全球购物
中国双语服务优势的在线购票及活动平台:247tickets
2018/10/26 全球购物
生日宴会策划方案
2014/06/03 职场文书
生物科学专业自荐书
2014/06/20 职场文书
国际商务专业毕业生自我鉴定2014
2014/09/27 职场文书
学校节水倡议书
2015/04/29 职场文书
2016年国陪研修感言
2015/11/18 职场文书
《猴王出世》教学反思
2016/02/23 职场文书
想要创业,那么你做好准备了吗?
2019/07/01 职场文书