Fre*_*its 6 html javascript jquery
我正在为Android和iPhone做一个Web应用程序.我的问题是,当用户去景观时我想刷新网页.由于我是javascript的初学者,我不知道该怎么做.请帮我
你可以使用orientationchange jQuery Mobile事件,然后做一个
window.location.reload();
Run Code Online (Sandbox Code Playgroud)
刷新页面.
例如:
$(function(){
// Set Inital orientation
// get the initial orientation from window which
// returns 0 for portrait and 1 for landscape
if(window.orientation == 0){
var ori = "portrait";
}else{
var ori = "landscape";
}
changeOrientation(ori);
// Orientation Change
// When orientation changes event is triggered
// exposing an orientation property of either
// landscape or portrait
$('body').bind('orientationchange',function(event){
changeOrientation(event.orientation)
})
// Change the style dependengt on orientation
function changeOrientation(ori){
// Remove all classes separated by spaces
$("#orientation").removeClass('portrait landscape');
$("#orientation").addClass(ori);
$("#orientation").html("<p>"+ori.toUpperCase()+"</p>");
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8117 次 |
| 最近记录: |