flip.js效果正常,flip:done内部的console.log也有效,但在flip:done内部调用的“ anotherfunc”不起作用。请帮忙。
function anotherfunc( ) {
console.log("its anotherfunc");
}
jQuery(document).ready(function($) {
//it is working here but not inside flip:done
anotherfunc();
$(".card").flip({
trigger: 'hover',
speed : 1000
});
$(".card").on('flip:done',function( ){
// this is also working
console.log('from inside flip:done');
// this is also working
console.log( $(this) );
// this is saying "is not a function"
$(this).anotherfunc();
});
});//on laod
最佳答案
您应该将其称为
anotherfunc($(this));
或像这样声明:
(function ($) {
$.fn.anotherfunc = function () {
// some code
}
})(jQuery);
然后您可以像这样使用它:
$(this).anotherfunc();
看看这个演示:https://jsfiddle.net/f8w14sbk/