由于上面的骨干事件,我无法检测到方向。它不起作用。除此之外,还有其他方法吗?通过绑定一个事件或其他东西?或者我的代码中有什么错误?事件orientationchange不起作用在主干
var HomeView = Backbone.View.extend({
template: Handlebars.compile(template),
events: {
"click .log_out": "log_out",
"click .prove": "prove",
"orientationchange": "onOrientationChange"
},
initialize: function() {
console.log("inhomeview");
this.render();
},
render: function() {
//var context = JSON.parse(JSON.stringify(this.model));//eliminare
var context = this.model;
var html = this.template(context);
console.log(html);
$('#pagina').empty();
$('#pagina').append(this.$el.html(html));
return this;
},
onOrientationChange: function() {
if (window.orientation === 90 || window.orientation === -90) {
alert('you are in landscape');
}
}
});
指http://stackoverflow.com/questions/1649086/detect-rotation-of-android-phone-in-the-browser- with-javascript – 2013-05-12 19:24:58
'onorientationchange'是窗口对象的属性。现在,您正试图将其应用于Backbone View。 – zvona 2013-05-12 19:28:39