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 相关文章推荐
ext jquery 简单比较
Apr 07 Javascript
javascript 词法作用域和闭包分析说明
Aug 12 Javascript
JQuery 选择和过滤方法代码总结
Nov 19 Javascript
创建js对象和js类的方法汇总
Dec 24 Javascript
JS控制文本域只读或可写属性的方法
Jun 24 Javascript
详解react服务端渲染(同构)的方法
Sep 21 Javascript
jquery ajaxfileuplod 上传文件 essyui laoding 效果【防止重复上传文件】
May 26 jQuery
JavaScript简易计算器制作
Jan 17 Javascript
vue 使用 canvas 实现手写电子签名
Mar 06 Javascript
node.js如何操作MySQL数据库
Oct 29 Javascript
uni-app使用countdown插件实现倒计时
Nov 01 Javascript
Vue3.0中Ref与Reactive的区别示例详析
Jul 07 Vue.js
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
thinkPHP分页功能实例详解
2017/05/05 PHP
php curl优化下载微信头像的方法总结
2018/09/07 PHP
laravel validate 设置为中文的例子(验证提示为中文)
2019/09/29 PHP
JavaScript版代码高亮
2006/06/26 Javascript
jquery 提交值不为空的元素示例代码
2013/05/10 Javascript
导入extjs、jquery 文件时$使用冲突问题解决方法
2014/01/14 Javascript
js如何实现点击标签文字,文字在文本框出现
2015/08/05 Javascript
JavaScript设计模式经典之工厂模式
2016/02/24 Javascript
seaJs使用心得之exports与module.exports的区别实例分析
2017/10/13 Javascript
vue中过滤器filter的讲解
2019/01/21 Javascript
react koa rematch 如何打造一套服务端渲染架子
2019/06/26 Javascript
React Native中ScrollView组件轮播图与ListView渲染列表组件用法实例分析
2020/01/06 Javascript
微信小程序接入腾讯云验证码的方法步骤
2020/01/07 Javascript
详细介绍解决vue和jsp结合的方法
2020/02/06 Javascript
JavaScript实现点击切换功能
2021/01/27 Javascript
Python批量创建迅雷任务及创建多个文件
2016/02/13 Python
Python 通过pip安装Django详细介绍
2017/04/28 Python
如何使用pyinstaller打包32位的exe程序
2019/05/26 Python
Django框架首页和登录页分离操作示例
2019/05/28 Python
python torch.utils.data.DataLoader使用方法
2020/04/02 Python
Python图像读写方法对比
2020/11/16 Python
Python 用__new__方法实现单例的操作
2020/12/11 Python
python中reload重载实例用法
2020/12/15 Python
CSS3截取字符串实例代码【推荐】
2018/06/07 HTML / CSS
CSS3制作文字半透明倒影效果的两种实现方式
2014/08/08 HTML / CSS
HTML5 embed标签定义和用法详解
2014/05/09 HTML / CSS
Bose加拿大官方网站:美国知名音响品牌
2019/03/21 全球购物
英国在线购买马术服装:EQUUS
2019/07/12 全球购物
德国家用电器购物网站:Premiumshop24
2019/08/22 全球购物
计算机工程学院个人求职信
2013/10/05 职场文书
员工年终演讲稿
2014/01/03 职场文书
致接力运动员广播稿
2014/02/17 职场文书
《陋室铭》教学反思
2014/02/26 职场文书
汇源肾宝广告词
2014/03/20 职场文书
教师“一帮一”结对子活动总结
2015/05/07 职场文书
班主任培训研修日志
2015/11/13 职场文书