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 相关文章推荐
JavaScript 浏览器验证代码(来自discuz)
Jul 17 Javascript
js jquery数组介绍
Jul 15 Javascript
jquery text(),val(),html()方法区别总结
Nov 04 Javascript
js实现匹配时换色的输入提示特效代码
Aug 17 Javascript
跟我学习javascript创建对象(类)的8种方法
Nov 20 Javascript
Angular下H5上传图片的方法(可多张上传)
Jan 09 Javascript
vue 项目如何引入微信sdk接口的方法
Dec 18 Javascript
vue实现选项卡及选项卡切换效果
Apr 24 Javascript
vue安装和使用scss及sass与scss的区别详解
Oct 15 Javascript
详解小程序如何避免多次点击,重复触发事件
Apr 08 Javascript
javascript实现数字时钟效果
Feb 06 Javascript
JS+CSS实现动态时钟
Feb 19 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
windows7配置Nginx+php+mysql的详细教程
2016/09/04 PHP
laravel 去掉index.php伪静态的操作方法
2019/10/12 PHP
JavaScript中实现块作用域的方法
2010/04/01 Javascript
JS面向对象编程 for Cookie
2010/09/19 Javascript
通过url查找a元素并点击
2014/04/09 Javascript
使用 js+正则表达式为关键词添加链接
2014/11/11 Javascript
javascript中setTimeout和setInterval的unref()和ref()用法示例
2014/11/26 Javascript
jQuery EasyUI Pagination实现分页的常用方法
2016/05/21 Javascript
jQuery如何获取动态添加的元素
2016/06/24 Javascript
easyui-combobox 实现简单的自动补全功能示例
2016/11/08 Javascript
jQuery NProgress.js加载进度插件的简单使用方法
2018/01/31 jQuery
使用FileReader API创建Vue文件阅读器组件
2018/04/03 Javascript
微信小程序实现左侧滑栏过程解析
2019/08/26 Javascript
解决layui-open关闭自身窗口的问题
2019/09/10 Javascript
js瀑布流布局的实现
2020/06/28 Javascript
举例详解Python中threading模块的几个常用方法
2015/06/18 Python
Python自动化部署工具Fabric的简单上手指南
2016/04/19 Python
python中找出numpy array数组的最值及其索引方法
2018/04/17 Python
使用50行Python代码从零开始实现一个AI平衡小游戏
2018/11/21 Python
python2.7实现复制大量文件及文件夹资料
2019/08/31 Python
python 命名规范知识点汇总
2020/02/14 Python
解决python ThreadPoolExecutor 线程池中的异常捕获问题
2020/04/08 Python
python 基于opencv去除图片阴影
2021/01/26 Python
详解CSS透明opacity和IE各版本透明度滤镜filter的最准确用法
2016/12/20 HTML / CSS
HTML5计时器小例子
2013/10/15 HTML / CSS
html5教程实现Photoshop渐变色效果
2013/12/04 HTML / CSS
塔吉特百货公司官网:Target
2017/04/27 全球购物
欧舒丹加拿大官网:L’Occitane加拿大
2017/10/29 全球购物
美国相机和电子产品零售商:Beach Camera
2020/11/26 全球购物
某公司的.net工程师面试题笔试题
2013/11/22 面试题
linux面试题参考答案(11)
2012/05/01 面试题
物流专业大学生职业生涯规划书范文
2014/01/15 职场文书
关于抽烟的检讨书
2014/02/25 职场文书
绍兴鲁迅故居导游词
2015/02/09 职场文书
Python-typing: 类型标注与支持 Any类型详解
2021/05/10 Python
python数字图像处理:图像简单滤波
2022/06/28 Python