Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于实验性-抖动扩展 #94

Open
tomieric opened this issue May 27, 2014 · 3 comments
Open

关于实验性-抖动扩展 #94

tomieric opened this issue May 27, 2014 · 3 comments

Comments

@tomieric
Copy link

还是喜欢旧版的弹层抖动功能

喜欢的可以参考一下。V6很简洁支持AMD很赞。

动手

把4.1.2种的实验性扩展源码复制到dialog.js中。

我这里放到

_trigger:function (id) {
      ...
}

后面

/**
 * 震动模式
 * 参考:http://www.planeart.cn/demo/artDialog/_doc/labs.html
 */
shake: function(){
    var timerId = null;
    var style = this._popup[0].style,
        p = [4, 8, 4, 0, -4, -8, -4, 0],
        fx = function () {
            style.marginLeft = p.shift() + 'px';
            if (p.length <= 0) {
                style.marginLeft = 0;
                clearInterval(timerId);
            };
        };
    p = p.concat(p.concat(p.concat(p)));
    timerId = setInterval(fx, 5);
    return this;
},

上滑下滑出现扩展

需修改popup.js中的show函数

     show: function (anchor, fn) {
               ...
               // this.reset().focus();
               typeof fn == "function" ? fn() : this.reset().focus();
               ...
     }

还是在dialog.js中进行扩展

/**
  * 下滑出现
  */
 slideDown: function(){
    var that = this;
    var wh = $(window).height();
    var oh = that._popup.height();
    var dt = this.fixed ? 0 : $(document).scrollTop();
    var top = (wh - oh) * 382 / 1000 + dt;

    that._popup.css({
        top: -(wh + oh)
    });

    this.show(null, function(){
        that._popup.animate({
            top: Math.max(parseInt(top), dt)
        }, 500);
    });
    return this;
 },
 /**
  * 上滑消失
  */
 slideUp: function(remove) {
    var that = this;
    var wh = $(window).height();
    var oh = that._popup.height();

    that._popup.animate({
        top: -(wh + oh)
    }, 600, function(){
        remove ? that.close().remove() : that.close();
    });
    return this;
}

建议通过模块扩展方法类似于dialog-plus.js来拓展不要去修改源码

@aofong
Copy link

aofong commented Jun 6, 2014

同样觉得这个抖动有用,之前就自己扩展进去了

@zotopteam
Copy link

/*
* 修改 扩展shake摇头方法
*/
$.extend(dialog.create.prototype,{
shake: function(){
var timerId = null;
var style = this._popup[0].style,
p = [4, 8, 4, 0, -4, -8, -4, 0],
fx = function () {
style.marginLeft = p.shift() + 'px';
if (p.length <= 0) {
style.marginLeft = 0;
clearInterval(timerId);
};
};
p = p.concat(p.concat(p.concat(p)));
timerId = setInterval(fx, 8);
return this;
}
});

@zotopteam
Copy link

可以直接扩展$.extend(dialog.create.prototype,{shake:function(){}}),然后使用的时候就可以像内部函数一样使用了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants