[英]How to customize Twitter Bootstrap popover hide animation
I would like to implement my own popover hide animation. 我想实现自己的popover hide动画。 Currently, I am modifying bootstrap.js directly. 目前,我正在修改bootstrap.js。
$.fn.popover = function (option) {
return this.each(function () {
var $this = $(this)
, data = $this.data('popover')
, options = typeof option == 'object' && option
if (!data) $this.data('popover', (data = new Popover(this, options)))
//original code
// if (typeof option == 'string') data[option]()
//custom code
if (typeof option == 'string') {
if (option === 'hide') {
//my customize animation here
}
else {
data[option]();
}
}
})
}
I would like to know if there are anyway so I can achieve a dynamic animation when I init the popover 我想知道是否还有,所以当我初始化popover时我可以实现动态动画
$('#target').popover({
hide: function () {
//my own animation
}
});
Nice question-brain-teaser! 好问题 - 脑筋急转弯! You can definitely do it. 你绝对可以做到。 Take a look how you can extend plugin without messing with original source code: 看一下如何在不破坏原始源代码的情况下扩展插件:
$.fn.popover = function (orig) {
return function(options) {
return this.each(function() {
orig.call($(this), options);
if (typeof options.hide == 'function') {
$(this).data('bs.popover').hide = function() {
options.hide.call(this.$tip, this);
orig.Constructor.prototype.hide.call(this);
};
}
});
}
}($.fn.popover);
Here we go! 开始了! We extended default popover functionality with our own. 我们使用自己的扩展功能扩展了默认弹出框。 Now lets use it: 现在让我们使用它:
$('.three').popover({
placement: 'bottom',
hide: function() {
$(this).animate({marginTop: -100}, function() {
$(this).css({marginTop: ''});
});
}
});
Above popover will have custom animation effect while hiding. 上面的popover将隐藏自定义动画效果。
Of course if you don't provide hide
option you will have default behavior. 当然,如果您不提供hide
选项,您将拥有默认行为。
Demo: http://jsfiddle.net/VHDwa/71/ 演示: http : //jsfiddle.net/VHDwa/71/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.