我希望在div显示(显示后)时调用一个函数.
有谁知道我怎么能这样做?我试着用这样的东西:
$(#someDiv).bind('show',function(){
alert('example')
});
Run Code Online (Sandbox Code Playgroud)
但我不确定我是否以正确的方式做到这一点,或者是否有可能实现这一目标.有任何想法吗?
Jel*_*Cat 18
以下代码(改编自http://maximeparmentier.com/2012/11/06/bind-show-hide-events-with-jquery/)将允许您使用$('#someDiv').on('show', someFunc);.
(function ($) {
$.each(['show', 'hide'], function (i, ev) {
var el = $.fn[ev];
$.fn[ev] = function () {
this.trigger(ev);
el.apply(this, arguments);
return el;
};
});
})(jQuery);
Run Code Online (Sandbox Code Playgroud)
它必须在 show() 方法的后回调中完成:
$('#someDiv').show('slide',function(){
alert('example')
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
50547 次 |
| 最近记录: |