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 相关文章推荐
在网页中控制wmplayer播放器
Jul 01 Javascript
Javascript操作cookie的函数代码
Oct 03 Javascript
Jquery颜色选择器ColorPicker实现代码
Nov 14 Javascript
JavaScript建立一个语法高亮输入框实现思路
Feb 26 Javascript
JS选项卡动态替换banner图片路径的方法
May 11 Javascript
jQuery用noConflict代替$的实现方法
Apr 12 jQuery
基于jquery trigger函数无法触发a标签的两种解决方法
Jan 06 jQuery
Vue父组件调用子组件事件方法
Feb 23 Javascript
React 组件间的通信示例
Jun 14 Javascript
vue实现一个炫酷的日历组件
Oct 08 Javascript
json_decode 索引为数字时自动排序问题解决方法
Mar 28 Javascript
javascript实现多边形碰撞检测
Oct 24 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 jquery 实现新闻标签分类与无刷新分页
2009/12/18 PHP
PHP多进程之pcntl_fork的实例详解
2017/10/15 PHP
gearman中任务的优先级和返回状态实例分析
2020/02/27 PHP
JavaScript 学习笔记 Black.Caffeine 09.11.28
2009/11/30 Javascript
JQuery 绑定select标签的onchange事件,弹出选择的值,并实现跳转、传参
2011/01/06 Javascript
JS鼠标事件大全 推荐收藏
2011/11/01 Javascript
js获取光标位置和设置文本框光标位置示例代码
2014/01/09 Javascript
jquery实现聚光灯效果的方法
2015/02/06 Javascript
JavaScript中property和attribute的区别详细介绍
2015/03/03 Javascript
js比较日期大小的方法
2015/05/12 Javascript
JQuery鼠标移到小图显示大图效果的方法
2015/06/10 Javascript
JavaScript如何实现对数字保留两位小数一位自动补零
2015/12/18 Javascript
浅析JavaScript函数的调用模式
2016/08/10 Javascript
JS实现上传图片实时预览功能
2017/05/22 Javascript
详解node-ccap模块生成captcha验证码
2017/07/01 Javascript
p5.js实现故宫橘猫赏秋图动画
2019/10/23 Javascript
Node.js API详解之 Error模块用法实例分析
2020/05/14 Javascript
对python 多个分隔符split 的实例详解
2018/12/20 Python
numpy.transpose()实现数组的转置例子
2019/12/02 Python
Zooplus葡萄牙:欧洲领先的网上宠物商店
2018/07/01 全球购物
澳大利亚婴儿、幼儿和儿童在线设计师商店:Smooch Baby
2019/02/16 全球购物
Linux文件操作命令都有哪些
2015/02/27 面试题
个人简历中的自我评价范例
2013/10/29 职场文书
积极分子思想汇报
2014/01/04 职场文书
财务部副经理岗位职责
2014/03/14 职场文书
优秀班主任经验交流材料
2014/06/02 职场文书
教育实践活动对照检查材料
2014/09/23 职场文书
派出所班子党的群众路线对照检查材料思想汇报
2014/10/01 职场文书
工会经费申请报告
2015/05/15 职场文书
奖金申请报告模板
2015/05/15 职场文书
导游词之京东大峡谷旅游区
2019/10/29 职场文书
MySQL的join buffer原理
2021/04/29 MySQL
低版本Druid连接池+MySQL驱动8.0导致线程阻塞、性能受限
2021/07/01 MySQL
PHP中国际化的字符串排序和比较对象详解
2021/08/23 PHP
python可视化大屏库big_screen示例详解
2021/11/23 Python
Python如何使用循环结构和分支结构
2022/04/13 Python