立足自己的代码在这个网址:http://api.jquerymobile.com/orientationchange/方向改变jQuery的帮助需要
我试图改变它,所以它可以显示每个方向不同的图像。在使用$("#someID").html(< img src.../ >);
但工作得很好出于某种原因,我不能得到它的工作,以及使用.addClass
可能有人请告诉我为什么下面似乎并没有屈服任何东西,但黑屏?
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>orientationchange demo</title>
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
<script src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
<script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
<style type="text/css">
.landscape {
background-image:url('images/landscape.jpg');
}
.portrait {
background-image:url('images/portrait.jpg');
}
</style>
</head>
<body>
<div id="orientation" class="landscape"></div>
<script>
// Bind an event to window.orientationchange that, when the device is turned,
// gets the orientation and displays it to on screen.
$(window).on("orientationchange", function(event) {
if (event.orientation=="landscape") {
//$("#orientation").removeClass("portrait");
$("#orientation").addClass("landscape");
return false;
} else if (event.orientation=="portrait") {
//$("#orientation").removeClass("landscape");
$("#orientation").addClass("portrait");
return false;
}
});
// You can also manually force this event to fire.
$(window).orientationchange();
</script>
</body>
</html>
好吧,我得到了它的尺寸为定义现在的工作,并结合addClass(类).removeClass(otherclass),但可能有人请告诉我我如何将这种变化的身体,而不是一个div?
您是否尝试改变设备的方向,又名,摇动它?此外,你可能想要给div#方向一个宽度和高度。 – dezman
正常工作,也许正如@watson所提到的那样,给予潜水高度和宽度http://fiddle.jshell.net/Palestinian/d6jY6/show/还可以删除类,而不仅仅是添加。 – Omar
@ watson + @ omar谢谢你的回复,我马上给它试一下=) –