Panel Events
优质
小牛编辑
125浏览
2023-12-01
描述 (Description)
要检测用户与面板的交互方式,您可以使用面板事件。 无论何时打开/关闭面板,它还可用于在JS中执行某些操作。
下表列出了Framework7支持的事件 -
S.No | 活动和描述 | 目标 |
---|---|---|
1 | open 只要面板开始打开动画,就会触发此事件。 | 面板元素 |
2 | opened 只要面板完成其打开动画,就会触发此事件。 | 面板元素 |
3 | close 每当启动面板关闭动画时,都会触发此事件。 | 面板元素 |
4 | closed 面板关闭动画完成后,将触发此事件。 | 面板元素 |
例子 (Example)
以下示例演示Framework7中的面板事件。 该示例检测用户与面板的交互并相应地显示事件消息。
<!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>Panel Events</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 = "panel-overlay"></div>
<div class = "panel panel-left panel-reveal">
<div class = "content-block">
<h2>Left Panel content</h2>
<p><a href = "#" data-panel = "right" class = "open-panel">Open Right Panel</a></p>
<p><a href = "#" class = "close-panel">Close me</a></p>
</div>
</div>
<div class = "panel panel-right panel-cover">
<div class = "content-block">
<h2>Right Panel content</h2>
<p><a href = "#" data-panel = "left" class = "open-panel">Open Left Panel</a></p>
<p><a href = "#" class = "close-panel">Close me</a></p>
</div>
</div>
<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"> </div>
<div class = "center">Side Panel Events</div>
<div class = "right"> </div>
</div>
</div>
<div class = "page-content">
<div class = "content-block">
<p> <a href = "#" class = "open-panel">Open Left Panel</a></p>
<p> <a href = "#" data-panel = "right" class = "open-panel">Open Right Panel</a></p>
</div>
</div>
</div>
</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;
$$('.panel-left').on('opened', function () {
myApp.alert('Left panel opened!!');
});
$$('.panel-left').on('close', function () {
myApp.alert('Left panel is closing!!');
});
$$('.panel-right').on('open', function () {
myApp.alert('Right panel is opening!!');
});
$$('.panel-right').on('closed', function () {
myApp.alert('Right panel closed!!');
});
</script>
</body>
</html>
输出 (Output)
让我们执行以下步骤,看看上面给出的代码是如何工作的 -
将上面给出的HTML代码保存为服务器根文件夹中的sidepanels_events.html文件。
以http://localhost/sidepanels_events.html打开此HTML文件,输出显示如下。
单击“ Open Left Panel链接时,此示例显示左侧面板,单击“ Open Right Panel链接时将显示右侧面板,并且当面板统计信息打开和关闭动画时将触发面板事件。