H5 - 侧滑效果实现

本文介绍如何使用APICloud框架实现侧滑菜单功能,包括打开和关闭侧滑界面的方法,以及展示承载侧滑界面的父页面和要弹出的侧滑界面的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

demo 地址: https://github.com/iotjin/JhAPICloud_iOS

cehua.gif

APICloud 跳到侧滑界面父界面的方法:openDrawerLayout
APICloud 弹出侧滑界面方法: openDrawerPane
APICloud 关闭弹出的侧滑界面: closeDrawerPane

cehua.html 是承载侧滑界面的父页面,cehua_right.html是要弹出的侧滑界面

api.openDrawerLayout({
    name: 'cehua',
    url: './cehua.html',
    animation: {
        type: 'push'
    },
    rightPane: {
        name: 'cehua_right',
        url: './cehua_right.html',
    }
});

cehua.html

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width"/>
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>侧滑承载界面</title>
    <link rel="stylesheet" type="text/css" href="../../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/aui.css" />
    <style type="text/css">

    .aui-bar{
      background: #45C01A;
    }
    </style>

    </head>

    <body >
      <header class="aui-bar aui-bar-nav" id="header">
          <a class="aui-pull-left aui-btn" tapmode onclick="closeWin()">
              <span class="aui-iconfont aui-icon-left"></span>
          </a>
          <div class="aui-title">侧滑</div>
          <a class="aui-btn aui-pull-right">
              <span class="aui-iconfont aui-icon-plus" tapmode onclick="clickNavRightItem()"></span>
          </a>
      </header>

    </body>

    <script type="text/javascript" src="../../../script/api.js"></script>
    <script>
    	apiready = function(){
            $api.fixStatusBar($api.byId('header'));

    	}

      function closeWin(){
          api.closeWin({
          });
      }

      function clickNavRightItem(){
        console.log("点击侧滑按钮");
        api.openDrawerPane({
            type: 'right'
        });
      }

    </script>

</html>

cehua_right.html

<!DOCTYPE HTML>
<html>

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="maximum-scale=1.0, minimum-scale=1.0, user-scalable=0, initial-scale=1.0, width=device-width" />
    <meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
    <title>侧滑</title>
    <link rel="stylesheet" type="text/css" href="../../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/aui.css" />
    <style type="text/css">
        body {
            background: #001041;
        }

        html {
            background: #001041;
        }

        .aui-bar {
            background: #001041;
        }

        .title {
            color: white;
            font-size: 20px;
        }

        .cell_BgColor {
            background: #001041;
        }

        .bgCell {
            padding-left: 15px;
            height: 60px;
            line-height: 60px;
            vertical-align: middle;
             cursor: pointer;
            /*border: 1px solid white;*/
        }

        .line {
            border-bottom: 1px solid white;
        }

        .name {
            color: white;
            font-size: 18px;
        }

        .clickSelColor {
            color: red;
            background: yellow;
        }
    </style>

</head>

<body>

    <header class="aui-bar aui-bar-nav" id="header">
        <a class="aui-pull-left aui-btn">
        </a>
    </header>

    <h2>标题</h2>

    <div class="aui-info aui-margin-t-10 aui-padded-l-10 aui-padded-r-10">
        <div class="aui-info-item">
            <img src="../../../icon/about_app.png" style="width:1.5rem" class="aui-img-round" /><span class="aui-margin-l-5 title">这是标题</span>
        </div>
    </div>

    <ul class="aui-list aui-list-in  cell_BgColor">
        <section id="CellList">
        </section>
    </ul>

</body>

<script type="text/html" id="template">
    {{each }}
    <div class="bgCell" tapmode="" onclick="clickItem('{{$value.id}}')">
        <div class="name"  id={{$value.id}}>{{$value.name}}</div>
        <div class="line"></div>
    </div>
    {{/each}}
</script>


<script type="text/javascript" src="../../../script/api.js"></script>
<script type="text/javascript" src="../../../script/template-web.js"></script>
<script>
    apiready = function() {

        $api.fixStatusBar($api.byId('header'));

        var ALLData = [{
            "id": "1",
            "name": "信息1",
        }, {
            "id": "2",
            "name": "信息2",
        }, {
            "id": "3",
            "name": "信息3",
        }, {
            "id": "4",
            "name": "信息4",
        }];
        let html = template('template', ALLData);
        $api.html($api.byId('CellList'), html);
        api.parseTapmode();

        var items = $api.domAll(".name");
        if ($api.hasCls(items[0], 'clickSelColor') == false) {
            $api.addCls(items[0], 'clickSelColor');
        }

    }

    function clickItem(id) {
      console.log("id---"+id);
      var items = $api.domAll(".name");
       for (var i = 0; i < items.length; i++) {
         if ( $api.hasCls(items[i], 'clickSelColor') ){
              $api.removeCls(items[i],'clickSelColor');
          }
       }

      var item= $api.byId(id);
      $api.addCls(item,'clickSelColor');
      api.closeDrawerPane();

    }



</script>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西半球

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值