- Framework7 教程
- Framework7 - 首页
- Framework7 - 概述
- Framework7 - 环境
- Framework7 组件
- Framework7 - 布局
- Framework7 - 导航栏
- Framework7 - 工具栏
- Framework7 - 搜索栏
- Framework7 - 状态栏
- Framework7 - 侧边栏
- Framework7 - 内容块
- Framework7 - 布局网格
- Framework7 - 覆盖层
- Framework7 - 预加载器
- Framework7 - 进度条
- Framework7 - 列表视图
- Framework7 - 手风琴
- Framework7 - 卡片
- Framework7 - 芯片
- Framework7 - 按钮
- Framework7 - 操作按钮
- Framework7 - 表单
- Framework7 - 标签页
- Framework7 - Swiper 滑块
- Framework7 - 照片浏览器
- Framework7 - 自动完成
- Framework7 - 选择器
- Framework7 - 日历
- Framework7 - 刷新
- Framework7 - 无限滚动
- Framework7 - 消息
- Framework7 - 消息栏
- Framework7 - 通知
- Framework7 - 延迟加载
- Framework7 样式
- Framework7 - 颜色主题
- Framework7 - 分割线
- Framework7 模板
- Framework7 - 模板概述
- Framework7 - 自动编译
- Framework7 - Template7 页面
- Framework7 快速点击
- Framework7 - 活动状态
- Framework7 - 长按事件
- Framework7 - 触摸波纹
- Framework7 有用资源
- Framework7 - 快速指南
- Framework7 - 有用资源
- Framework7 - 讨论
Framework7 - 从 HTML 打开和关闭弹出窗口
描述
所需的弹出窗口可以使用链接上的特殊类和数据属性来打开和关闭。以下语句简要描述了如何打开/关闭弹出窗口 -
要打开弹出窗口,请向任何 HTML 元素添加 open-popover 类,并且可以使用 close-popover 类关闭弹出窗口。
当您在应用程序中有多个弹出窗口时,需要将 data-popover=".mypopover" 属性指定到相应的弹出窗口。
当使用此方法(从 HTML)打开弹出窗口时,弹出窗口将自动放置在我们点击以调用此弹出窗口的元素周围。
示例
以下示例演示了在 Framework7 中从 HTML 打开和关闭弹出窗口 -
<!DOCTYPE html> <html> <head> <meta name = "viewport" content = "width = device-width, initial-scale = 1, maximum-scale = 1, minimum-scale = 1, user-scalable = no, minimal-ui" /> <meta name = "apple-mobile-web-app-capable" content = "yes" /> <meta name = "apple-mobile-web-app-status-bar-style" content = "black" /> <title>Open and close Popover From HTML</title> <link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.min.css" /> <link rel = "stylesheet" href = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/css/framework7.ios.colors.min.css" /> </head> <body> <div class = "views"> <div class = "view view-main"> <div class = "pages"> <div data-page = "home" class = "page navbar-fixed"> <div class = "navbar"> <div class = "navbar-inner"> <div class = "left"> <a href = "#" data-popover = ".popover-menus" class = "link open-popover">Menus</a></div> <div class = "center">Open and close Popover From HTML</div> <div class = "right"> <a href = "#" data-popover = ".popover-about" class = "link open-popover">About</a></div> </div> </div> <div class = "page-content"> <div class = "content-block"> <p><a href = "#" data-popover = ".popover-about" class = "open-popover">Open About Popover</a></p> <p><a href = "#" data-popover = ".popover-menus" class = "open-popover">Open Menus Popover</a></p> </div> </div> </div> </div> </div> </div> <style>.popover{width:200px;}</style> <div class = "popover popover-about"> <div class = "popover-angle"></div> <div class = "popover-inner"> <div class = "content-block"> <p>About</p> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ac diam ac quam euismod porta vel a nunc.</p> </div> </div> </div> <div class = "popover popover-menus"> <div class = "popover-angle"></div> <div class = "popover-inner"> <div class = "list-block"> <ul> <li><a href = "#" class = "list-button item-link">Menu 1</a></li> <li><a href = "#" class = "list-button item-link">Menu 2</a></li> <li><a href = "#" class = "list-button item-link">Menu 3</a></li> <li><a href = "#" class = "list-button item-link">Menu 4</a></li> <li><a href = "#" class = "list-button item-link">Menu 5</a></li> </ul> </div> </div> </div> <script type = "text/javascript" src = "https://cdnjs.cloudflare.com/ajax/libs/framework7/1.4.2/js/framework7.min.js"></script> <script> var myApp = new Framework7(); var $$ = Dom7; </script> </body> </html>
输出
让我们执行以下步骤来了解上面给出的代码是如何工作的 -
将上面给出的 HTML 代码保存为 popover_open_close_html.html 文件,放在您的服务器根目录文件夹中。
以 https://127.0.0.1/popover_open_close_html.html 的方式打开此 HTML 文件,输出结果如下所示。
当您点击第一个链接时,将打开关于弹出窗口。类似地,当您点击第二个链接时,将打开具有多个菜单项的菜单弹出窗口。
菜单和关于弹出窗口也可以通过点击顶部的菜单和关于选项来打开。弹出窗口将从 HTML 中打开和关闭。
当您点击链接时,弹出窗口将使用 popover 类打开,如果您点击鼠标外部,弹出窗口将关闭。
framework7_overlays.htm
广告