JSAPI

  • Since 10.0.8

    setLandscape

    横竖屏自由切换 setLandscape

    使用方法

     // 切换横屏
    AlipayJSBridge.call('setLandscape', {}, function(e){
      console.log(e)
    });
    
    // 切换竖屏
    AlipayJSBridge.call('setPortrait', {}, function(e){
      console.log(e)
    });
    

    代码演示

    setLandscape

    <h1>点击以下按钮看不同效果</h1>
    <a href="javascript:void(0)" class="btn setLandscape">点击setLandscape</a>
    <a href="javascript:void(0)" class="btn setPortrait">点击setPortrait</a>
    
    <script>
    function ready(callback) {
      // 如果jsbridge已经注入则直接调用
      if (window.AlipayJSBridge) {
        callback && callback();
      } else {
        // 如果没有注入则监听注入的事件
        document.addEventListener('AlipayJSBridgeReady', callback, false);
      }
    }
    ready(function() {
      document.querySelector('.setLandscape').addEventListener('click', function() {
        AlipayJSBridge.call('setLandscape', {}, function(e) {
          alert(JSON.stringify(e))
        });
      });
    
      document.querySelector('.setPortrait').addEventListener('click', function() {
        AlipayJSBridge.call('setPortrait', {}, function(e) {
          alert(JSON.stringify(e))
        });
      });
    });
    </script>
    

    API

    AlipayJSBridge.call('setLandscape',{
    }, fn)