由於上面的骨幹事件,我無法檢測到方向。它不起作用。除此之外,還有其他方法嗎?通過綁定一個事件或其他東西?或者我的代碼中有什麼錯誤?事件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