Jquery 评估方向事件并设置值?
如果在发生方向更改时触发了onChange函数,那么如何在onChange中设置一个值来更新jquery选择器。例如:Jquery 评估方向事件并设置值?,jquery,orientation,screen-orientation,device-orientation,Jquery,Orientation,Screen Orientation,Device Orientation,如果在发生方向更改时触发了onChange函数,那么如何在onChange中设置一个值来更新jquery选择器。例如: $(document).ready(function(){ var onChanged = function() { if(window.orientation == 90 || window.orientation == -90){ image = '<img src="images/land_
$(document).ready(function(){
var onChanged = function() {
if(window.orientation == 90 || window.orientation == -90){
image = '<img src="images/land_100.png">';
}else{
image = '<img src="images/port_100.png">';
}
}
$(window).bind(orientationEvent, onChanged).bind('load', onChanged);
$('#bgImage').html(image); //won't update image
});
$(文档).ready(函数(){
var onChanged=function(){
如果(window.orientation==90 | | window.orientation==-90){
图像='';
}否则{
图像='';
}
}
$(window).bind(orientationEvent,onChanged).bind('load',onChanged);
$('#bgImage').html(图像);//不会更新图像
});
您需要将图像更新放在onChanged函数中,以便每次方向改变时,图像HTML都会改变
$(document).ready(function(){
// The event for orientation change
var onChanged = function() {
// The orientation
var orientation = window.orientation,
// If landscape, then use "land" otherwise use "port"
image = orientation == 90 || orientation == -90 ? "land" : "port";
// Insert the image
$('#bgImage').html('<img src="images/'+image+'_100.png">');
};
// Bind the orientation change event and bind onLoad
$(window).bind(orientationEvent, onChanged).bind('load', onChanged);
});
$(文档).ready(函数(){
//改变方向的事件
var onChanged=function(){
//方向
变量方向=窗口方向,
//如果是景观,则使用“土地”,否则使用“港口”
图像=方向==90 | |方向==-90?“陆地”:“港口”;
//插入图像
$('#bgImage').html('');
};
//绑定方向更改事件并绑定onLoad
$(window).bind(orientationEvent,onChanged).bind('load',onChanged);
});