直到今天,我在 JQM 项目上设置了自定义页面转换,如下所示:
function myTransitionHandler(name, reverse, $to, $from)
{
deferred = new $.Deferred();
//transition stuff done here
setTimeout(function(){
deferred.resolve(name, reverse, $to, $from)
}, 500)
return deferred.promise();
}
$.mobile.transitionHandlers["myTransition"] = myTransitionHandler;
我今天将 JQM 从 1.3 升级到 1.4,现在当我更改页面时,我在控制台上看到以下错误:
Uncaught TypeError: Object #<Object> has no method 'transition'
看看changelog对于 v 1.4,有一条特定的线突出,
Added transition handler object
(93b0b48)
我很确定这是造成这种情况的原因,但作为一个相当缺乏经验的程序员,我不知道应该对我的项目进行哪些更改以适应这一点。任何帮助表示赞赏...
最佳答案
深入研究代码,我发现 jQuery Mobile 1.4 默认转换处理程序现在是这样定义的:
$.mobile.transitionHandlers = {
"sequential": $.mobile.SerialTransition,
"simultaneous": $.mobile.ConcurrentTransition
};
查看 $.mobile.SerialTransition 对象定义,您可以发现它是一个扩展 $.mobile.Transition 对象的对象。以下是取自 jQuery Mobile 1.4 的代码。
(function( $ ) {
$.mobile.SerialTransition = function() {
this.init.apply(this, arguments);
};
$.extend($.mobile.SerialTransition.prototype, $.mobile.Transition.prototype, {
sequential: true,
beforeDoneOut: function() {
if ( this.$from ) {
this.cleanFrom();
}
},
beforeStartOut: function( screenHeight, reverseClass, none ) {
this.$from.animationComplete($.proxy(function() {
this.doneOut( screenHeight, reverseClass, none );
}, this ));
}
});
})( jQuery );
因此,如果您想创建自定义转换处理程序,则不能再使用简单的函数,而必须使用这样的对象。
此外,如果您想了解有关 $.mobile.Transition 对象的更多信息,请下载 jQuery Mobile unminified 开发 js 并查看第 #5903 行
关于javascript - JQM 1.4.0 上的自定义转换设置出现 "has no method ' 转换 '"错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20806208/