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操纵Cookie实现购物车程序
Feb 15 Javascript
网站页面自动跳转实现方法PHP、JSP(下)
Aug 01 Javascript
javascript抖动元素的小例子
Oct 28 Javascript
如何在指定的地方插入html内容和文本内容
Dec 23 Javascript
JS获取URL中参数值(QueryString)的4种方法分享
Apr 12 Javascript
Javascript 调用 ActionScript 的简单方法
Sep 22 Javascript
jquery插入兄弟节点的操作方法
Dec 07 Javascript
jquery dataview数据视图插件使用方法
Dec 23 Javascript
svg动画之动态描边效果
Feb 22 Javascript
Ionic2调用本地SQlite实例
Apr 22 Javascript
JS使用tofixed与round处理数据四舍五入的区别
Oct 25 Javascript
p5.js入门教程之图片加载
Mar 20 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
js 判断 enter 事件
2009/02/12 Javascript
浅析javascript中function 的 length 属性
2014/05/27 Javascript
元素绑定click点击事件方法
2015/06/08 Javascript
Kindeditor在线文本编辑器如何过滤HTML
2016/04/14 Javascript
jquery使用on绑定a标签无效 只能用live解决
2016/06/02 Javascript
AngularJS基础 ng-selected 指令简单示例
2016/08/03 Javascript
深入理解JS DOM事件机制
2016/08/06 Javascript
半个小时学json(json传递示例)
2016/12/25 Javascript
nodejs利用ajax实现网页无刷新上传图片实例代码
2017/06/06 NodeJs
微信小程序使用toast消息对话框提示用户忘记输入用户名或密码功能【附源码下载】
2017/12/09 Javascript
vue项目中公用footer组件底部位置的适配问题
2018/05/10 Javascript
d3绘制基本的柱形图的实现代码
2018/12/12 Javascript
在微信小程序中保存网络图片
2019/02/12 Javascript
JavaScript中reduce()的5个基本用法示例
2020/07/19 Javascript
让python json encode datetime类型
2010/12/28 Python
在Python的框架中为MySQL实现restful接口的教程
2015/04/08 Python
简介Python设计模式中的代理模式与模板方法模式编程
2016/02/02 Python
python+django快速实现文件上传
2016/10/24 Python
Python3.0中普通方法、类方法和静态方法的比较
2019/05/03 Python
python3获取当前目录的实现方法
2019/07/29 Python
Django CSRF跨站请求伪造防护过程解析
2019/07/31 Python
python 扩展print打印文件路径和当前时间信息的实例代码
2019/10/11 Python
python实现网页录音效果
2020/10/26 Python
python中复数的共轭复数知识点总结
2020/12/06 Python
python 三种方法提取pdf中的图片
2021/02/07 Python
台湾专柜女包:KINAZ
2019/12/26 全球购物
销售总经理岗位职责
2014/03/15 职场文书
家长会主持词
2014/03/26 职场文书
学历公证书范本
2014/04/09 职场文书
俞敏洪北大演讲稿
2014/05/22 职场文书
三严三实对照检查材料
2014/09/22 职场文书
电工实训报告总结
2014/11/05 职场文书
2016自主招生校长推荐信范文
2015/03/23 职场文书
2015年大学迎新晚会总结
2015/07/16 职场文书
golang判断key是否在map中的代码
2021/04/24 Golang
Python实现学生管理系统并生成exe可执行文件详解流程
2022/01/22 Python