Example iOS

优质
小牛编辑
129浏览
2023-12-01

描述 (Description)

Framework7允许您在iOS布局中使用不同类型的通知。

例子 (Example)

以下示例演示了在Framework7中使用iOS通知 -

<!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>Notifications</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">
      <link rel="stylesheet" href="custom.css">
   </head>
   <body>
      <div>
         <div>
            <div>
               <div data-page="home">
                  <div>
                     <div>
                        <div>Notifications</div>
                     </div>
                  </div>
                  <div>
                     <div>
                        <p><a href="#">Default</a></p>
                        <p><a href="#">Full-layout notification</a></p>
                        <p><a href="#">Custom image</a></p>
                        <p><a href="#">Callback on close</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 mainView = myApp.addView('.view-main');
         var $$ = Dom7;
         $$('.notification-default').on('click', function () {
            myApp.addNotification({
               title: 'Default notification',
               message: 'This is default notification with title and message'
            });
         });
         $$('.notification-full').on('click', function () {
            myApp.addNotification({
               title: 'Full-layout',
               subtitle: 'Notification subtitle',
               message: 'You have a new mail',
               media: '<i></i>'
            });
         });
         $$('.notification-custom').on('click', function () {
            myApp.addNotification({
               title: 'Event',
               subtitle: 'You missed an event at your place..',
               message: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
                  Aenean ut posuere erat. Aliquam sed molestie risus, quis tincidunt dui.',
                  media: '<img width="44" height="44" style="border-radius:100%" src="/framework7/images/pic2.jpg">'
            });
         });
         $$('.notification-callback').on('click', function () {
            myApp.addNotification({
               title: 'Album',
               subtitle: 'A Wonderful Myth',
               message: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.
                  Aliquam sed molestie risus, quis tincidunt dui.',
                  media: '<img width="44" height="44" style="border-radius:100%" src="/framework7/images/pic.jpg">',
               onClose: function () {
                  myApp.alert('Callback activated. Notification closed');
               }
            });
         });
      </script>
   </body>
</html>

输出 (Output)

让我们执行以下步骤,看看上面给出的代码是如何工作的 -

  • 将上面给出的HTML代码保存为服务器根文件夹中的notifications_iOS.html文件。

  • 以http://localhost/notifications_iOS.html打开此HTML文件,输出显示如下。

  • 此示例在iOS布局中提供不同类型的通知,例如默认通知,完整布局通知,自定义消息通知等。