mui popover 自定义 弹出位置 显示 隐藏

mui popover

一.要显示、隐藏弹出菜单插件,mui推荐使用锚点方式.

1.页面顶部导航栏、底部工具栏固定位置
<header class="mui-bar mui-bar-nav">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left">a>
    <a id="menu" class="mui-action-menu mui-icon mui-icon-bars mui-pull-right" href="#topPopover">a>
    <h1 class="mui-title">右上角弹出菜单h1>
header>
<footer class="mui-bar mui-bar-footer">
    <a href="#bottomPopover" class="mui-btn mui-btn-link mui-pull-right">右下角弹出菜单a>
footer>

<div id="topPopover" class="mui-popover">
    <div class="mui-popover-arrow">div>
    <div class="mui-scroll-wrapper">
        <div class="mui-scroll">
            <ul class="mui-table-view">
                <li class="mui-table-view-cell"><a href="#">Item1a>li>
                <li class="mui-table-view-cell"><a href="#">Item2a>li>
                <li class="mui-table-view-cell"><a href="#">Item3a>li>
                <li class="mui-table-view-cell"><a href="#">Item4a>li>
                <li class="mui-table-view-cell"><a href="#">Item5a>li>
            ul>
        div>
    div>
div>

<div id="bottomPopover" class="mui-popover mui-popover-bottom">
    <div class="mui-popover-arrow">div>
    <div class="mui-scroll-wrapper">
        <div class="mui-scroll">
            <ul class="mui-table-view">
                <li class="mui-table-view-cell"><a href="#">Item1a>li>
                <li class="mui-table-view-cell"><a href="#">Item2a>li>
                <li class="mui-table-view-cell"><a href="#">Item3a>li>
                <li class="mui-table-view-cell"><a href="#">Item4a>li>
                <li class="mui-table-view-cell"><a href="#">Item5a>li>
                <li class="mui-table-view-cell"><a href="#">Item6a>li>
            ul>
        div>
    div>
div>
2.其它区域要使用弹出菜单,都要准确计算物理位置,从而实现弹出菜单的绝对定位; mui封装的手势事件中,可以获得点击位置,通过这些位置可实现任意区域的弹出菜单显示
<div class="mui-content">
    <div class="mui-content-padded">
        <p>
            <a href="#middlePopover" class="mui-btn mui-btn-primary mui-btn-block mui-btn-outlined" style="padding: 5px 20px;">打开弹出菜单a>
        p>
    div>
div>

<div id="middlePopover" class="mui-popover">
    <div class="mui-popover-arrow">div>
    <div class="mui-scroll-wrapper">
        <div class="mui-scroll">
            <ul class="mui-table-view">
                <li class="mui-table-view-cell"><a href="#">Item1a>li>
                <li class="mui-table-view-cell"><a href="#">Item2a>li>
                <li class="mui-table-view-cell"><a href="#">Item3a>li>
                <li class="mui-table-view-cell"><a href="#">Item4a>li>
                <li class="mui-table-view-cell"><a href="#">Item5a>li>
                <li class="mui-table-view-cell"><a href="#">Item6a>li>
            ul>
        div>
    div>
div>

二.通过js的方式控制弹出菜单,实现任意元素上弹出.

有时要做点击页面顶部导航栏、底部工具栏也在某一其他元素上弹出时,就适合用js的方式控制.

//方法:
    mui(弹出层元素).popover(status[,anchor]);
//示例:
    mui(弹出层元素).popover('show ');//show hide toggle
     //传入toggle参数,用户也无需关心当前是显示还是隐藏状态,mui会自动识别处理;
     mui(弹出层元素).popover('toggle',document.getElementById(显示位置元素)); 
<header class="mui-bar mui-bar-nav"> 
  <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left">a>
  <a id="menu" class="mui-action-menu mui-icon mui-icon-bars mui-pull-right" href="#topPopover">a>
  <h1 class="mui-title">右上角弹出菜单h1>
header>

    

        
    
            
   

// 点击弹出 mui('.mui-bar').on('tap','.mui-btn',function(){ mui('#topPopover').popover('show',document.getElementById("list")); // 将id为list的元素放在想要弹出的位置 });

 

转载于:https://www.cnblogs.com/ooo0/p/6114545.html

你可能感兴趣的:(人工智能)