栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > JavaScript

基于OO的动画附加插件,可以实现弹跳、渐隐等动画效果 分享

JavaScript 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

基于OO的动画附加插件,可以实现弹跳、渐隐等动画效果 分享

前言:前段时间一直都好忙也就好久没有写些东西了,最近手上的事刚好告些段落了,把以前空写的写插件都拿出来分享下吧,希望对大家有些帮助,也希望有高手能帮忙指点下我的写不足和错误,一直以来自己写的东西都是在用,性能方面个人只能尽量靠近问题还很多……真心求指点;
插件简介:执行渐隐等动画效果,可以这个插件为一个附加插件 可以配合前面我发的一个弹出层 等等之类的东西用增加js展示的趣味性,
使用方法:在下面的js代码里面前面写了,大家可以看看直接复制粘贴就可以用了有问题可以联系我JS代码如下 展示方式可以复制下面的HTML查看
[javascript]
复制代码 代码如下:


//animation
var ani = function(){this.init.apply(this,arguments)}
ani.prototype = {
    _id:function(i){
        if(!i) return;
        return typeof i != "string" && i.nodeType === 1 ? i : document.getElementById(i);
    },
    init:function(e,s,callback){
        this.e = this._id(e);
        this.setInit(s||{});
        var maxS = parseInt(this.s.maxVal),speed = maxS==0?Math.max(this.getSty(this.e,this.s.sty),1):maxS/5;
        this.fun(speed,maxS,callback)
    },
    formula:function(x){
        var f;
        switch(this.s.effect){
            case 0:
                f = "outQuad";
                break;
            case 1:
                f = "inQuad";
                break;
            case 2:
                f = "bounce";
                break;
            default:
                f = "easeInBack";
        }
        this.tween ={
            outQuad:function(pos){return Math.pow(pos, 2)},//outQuad
            inQuad:function(pos){return -(Math.pow((pos-1),2)-1)},//inQuad
            bounce:function(pos){//bounce
                if (pos < (1 / 2.75)) {
                    return (7.5625 * pos * pos);
                } else if (pos < (2 / 2.75)) {
                    return (7.5625 * (pos -= (1.5 / 2.75)) * pos + .75);
                } else if (pos < (2.5 / 2.75)) {
                    return (7.5625 * (pos -= (2.25 / 2.75)) * pos + .9375);
                } else {
                    return (7.5625 * (pos -= (2.625 / 2.75)) * pos + .984375);
                }
            },
            easeInBack:function(pos){var s = 1.70158;return (pos) * pos * ((s + 1) * pos - s);}
        };
        return this.tween[f](x);
    },
    findAry:function(attr){
        var rg = ["width","height","top","bottom","left","right","margin","padding"];
        for(var z in rg){
            if(rg[z]==attr) return true;
        }
        return false;
    },
    setInit:function(s){
        this.s = {
            sty:"width",
            curClass:"",
            maxVal:0,//效果最大值
            effect:1//执行效果
        }
        for(i in s) this.s[i] = s[i];
    },
    setSty:function(x){
        var attr = this.s.sty;
        if(this.findAry(attr)){
            this.e.style[attr] = x + 'px';
            var isIE6 = navigator.appVersion.indexOf("MSIE 6")>-1;
            isIE6&&attr=="top"&&(this.e.style[attr] = x + document.documentElement.scrollTop + 'px');
        }else if(attr=="opacity"){
            this.s.maxVal===1&&(this.e.style.display = "block");
            this.e.style.opacity = x;
            this.e.style.filter = "alpha(opacity="+x*100+")";
        }else{
            this.e[this.s.sty] = x
        }
    },
    getSty:function(e,s){
        var val = e.currentStyle?e.currentStyle[s]:document.defaultView.getComputedStyle(e,null)[s];
        return parseInt(val)||0;
    },
    fun:function(f,m,callback){
        var D = Date,t = new D,e,T = 500,_this = this;
        return e = setInterval(function() {
            var z = Math.min(1, (new D - t) / T),
                c = _this.s.curClass,
                curC = _this.e.className;
            _this.setSty( + f + (m - f) * _this.formula(z));
            if (z == 1) {
                if (callback && typeof callback == 'function') callback();
                _this.s.maxVal==0&&(_this.e.getAttribute("style"))&&(_this.e.style.display="none");
                if(c!=""&&curC.indexOf(c)<0)_this.e.className += c;
                clearInterval(e);
            }
        },10);
    }
}

这是这个js展示的第一个DEMO1:
[html]
复制代码 代码如下:




test

    div,h6,body{padding:0;margin:0;}
        div,h6{font:bold 12px/24px 'Tahoma';text-indent:15px;}
    .car-mod{position:relative;width:200px;}
        .car-menu{width:200px;background:#c06;cursor:pointer;color:#fff;}
        .car-box{border:2px solid #c06;width:300px;display:none;}
        .car-box h6{background-color:#f5f5f5;background-image:-moz-linear-gradient(#f5f5f5,#fff);}
        .things{border-top:1px solid #ccc;padding:50px 15px;}




   

    购物车

   
      我的购物车
     
   

   




这个是基于前面的那个弹出层的demo版本的效果,这个效果必须复制前面的弹出层的js哦部分代码如下
[html]
复制代码 代码如下:




弹出层事例

    div{padding:0;margin:0;}
    .wra{margin:0 auto;width:1000px;overflow:hidden;}
    .menu{border:1px solid #ccc;background:#000;color:#fff;width:250px;height:30px;font:14px/30px '微软雅黑';text-align:center;text-shadow:1px 1px 2px #f5f5f5;cursor:pointer;}
    .con{border:1px solid #000;background:#fff;padding:30px;width:500px;height:200px;position:fixed;top:-150%;left:50%;margin:-100px 0 0 -250px;display:none;z-index:999;}
    .close{display:block;position:absolute;right:10px;top:10px;cursor:pointer;font:bold 14px Arial;-moz-transition:-moz-transform .5s ease-in 0s;}
    .close:hover{-moz-transform:rotate(360deg);}







    点击弹出层

   
    X
        弹出层内容
 
 
 
 



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/111097.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号