`

orientationchange实现手机横竖屏事件

阅读更多

这个主要是实现手机页面相册横屏时能单独作为幻灯片播放,前提一定要让手机的横屏功能开启才可以。主要是通过iframe调用不同的引用页面实现,下面附上具体代码,可以尝试实现。

 

<!doctype html>
<html>
<head>
<meta charset="gb2312">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
<title>横竖屏</title>
<script src="../script/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(function(){
  var hei=$(window).height();
  $("iframe").height(hei); 
 
function orient() {

//判断是否为竖屏

 if (window.orientation == 0 || window.orientation == 180) {
    //alert("竖屏");
  $("body").attr("class", "portrait");
  
  orientation ="portrait";
  
  $("#ifm").attr("src","Carousel.html");
  return false;

    }

//判断是否为横屏

   else if (window.orientation == 90 || window.orientation == -90) {
     //alert("横屏");
  $("body").attr("class", "landscape");
  
  orientation = "landscape";
  
  $("#ifm").attr("src","Carousel1.html");
  
  return false;
 }

}
    //orientationchange手机横竖屏出发事件
 $(window).bind('orientationchange', function(e){
  
   orient();
  
 });
})

</script>


</head>

<body>
<iframe src="Carousel.html" frameborder="0" marginheight="0" marginwidth="0" frameborder="0" scrolling="auto" id="ifm" name="ifm"  style="width:100%"> </iframe>
</body>
</html>

分享到:
评论

相关推荐

    更靠谱的H5横竖屏检测方法(js代码)

    前不久,做了一个H5项目,需要在横竖屏变化时,做一些处理。毫无疑问,需要使用orientationchange来监听横竖屏的变化。 方案一: // 监听 orientation changes window.addEventListener("orientationchange", ...

    基于media特性实现对原生orientationchange的修复

    orientationchange-fix是一个基于CSS3@media特性实现对原生orientationchange修复的实用库,它让orientation detection更加可靠,更加easy。

    js实现rem自动匹配计算font-size的示例

    下面是相关JavaScript的实现代码: (function (doc, win) { var docEl = doc.documentElement, resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () {

    使用JavaScript判断手机浏览器是横屏还是竖屏问题

    //判断手机横竖屏状态: function hengshuping(){ if(window.orientation==180||window.orientation==0){ alert&#40;竖屏状态!&#41; } if(window.orientation==90||window.orientation==-90){ alert&#40;横屏状态!...

    javascript检测移动设备横竖屏

    (2)orientationchange 是一个event,在设备旋转时,会触发此事件,如同PC上使用的resize事件。 这两个搭配起来使用,很容易就能获得设备的横竖屏状态,代码如下: (function(){ var init = function(){

    js实现适配不同的屏幕大小

    resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () { var clientWidth = docEl.clientWidth; if (!clientWidth) return; // 根据设备的比例调整初始font-...

    jQuery mobile 移动web(6)

    jquery mobile 针对移动端设备的事件... orientationchange 事件函数当移动设备的方向发生改变触发,在事件的回调函数内的第二个参数返回一个用于识别当前方向的参数,  该参数有两种返回值:portrait(纵向)landscar

    orientationchangeend:当设备的方向改变并且相关的旋转动画已经完成时,orientationchangeend 事件被触发

    当设备的方向改变时, orientationchange事件被触发。 – 这个定义忽略了在window.orientation属性改变之后,但在 UI 中反映方向之前触发事件。 检查元素的尺寸(例如window.innerWidth或window.innerHeight )给...

    移动适配的几种方案(三种方案)

    resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () { var clientWidth = docEl.clientWidth; if (!clientWidth) return; docEl.style.fontSize = 100 * ...

    javascript判断iphone/android手机横竖屏模式的函数

    查了不少资料,最后结论如下: 代码如下: function orientationChange(){ switch(window.orientation) { case 0: // Portrait case 180: // Upside-down Portrait // Javascript to setup Portrait view break;...

    custom-resize

    如果您不想在这种情况下进行任何不必要的计算,则可以使用orientationchange事件。 与这个问题orientationchange但是事件是,在很多情况下(尤其是在Android),它触发的方向已经改变了。 因此,您的函数所依赖的...

    微信小程序中单位rpx和rem的使用

    前言 这篇文章主要给大家讲解了rpx和rem应用于微信小程序,如果你还没有入门,建议先从下面看起  微信小程序官方文档  &gt;web app变革之rem  &gt;rpx单位官方文档 ... 'orientationchange' : 'resize',

    几行js代码实现自适应

    在javascript写下如下几行:... resizeEvt = 'orientationchange' in win? 'orientationchange' : 'resize', recalc = function () { var clientWidth = docEl.clientWidth; if (clientWidth === undefined) return;

    58同城招聘季页面

    var supportsOrientationChange = 'onorientationchange' in window ? 'orientationchange' : 'resize'; var timeoutId;

    微信小程序中rpx与rem单位使用

    本文讲解rpx和rem应用于微信小程序,如果你还没有入门,建议先从下面看起: 微信小程序官方文档 ... resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = funct

    MatchDimension:跨浏览器Javascript视口感知

    侦听视口更改的选项-在resize和orientationchange更改事件上绑定函数-例如matchMedia.addListener 编写简单,字符少 局限性: 仅允许像素单位 用法: 只需在代码中包含库[removed][removed] if ( mtchD ( 'min-w

    详解vue-cli中使用rem,vue自适应

    1.rem.js内容  !...  o = "orientationchange" in n ? "orientationchange" : "resize",  a = function() {  var n = t.clientWidth || 320;  n &gt; 720 && (n = 720);  t.style.f

    clipjs:在方向改变时,滚动你回到你在内容中的位置

    触发orientationchange事件后,它会将您向上/向下滚动到该元素的顶部。 它需要 jQuery,并且已经验证至少可以追溯到 1.10.2(wootheme 的画布使用的版本)。 我已经在运行 iOS 7 的 iPod touch 上对其进行了测试。...

    代码分析vue中如何配置less

    安装 npm install --save-dev less less-loader npm install --save-dev style-loader css-loader... resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize', recalc = function () { var c

Global site tag (gtag.js) - Google Analytics