html
1 <!DOCTYPE HTML> 2<html> 3<head> 4 <meta charset="utf-8"> 5 <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover"> 6 <meta http-equiv="Content-Security-Policy" content="default-src * data: gap: https://ssl.gstatic.com; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'"> 7 <script src="components/loader.js"></script> 8 <script src="lib/onsenui/js/onsenui.min.js"></script> 9 10 <link rel="stylesheet" href="components/loader.css"> 11 <link rel="stylesheet" href="lib/onsenui/css/onsenui.css"> 12 <link rel="stylesheet" href="lib/onsenui/css/onsen-css-components.css"> 13 <link rel="stylesheet" href="css/style.css"> 14 <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> 15 16 <script> 17 ons.ready(function(){ 18 document.addEventListener('init', function(event) { 19 time(); 20 setInterval(time,1000); 21 }, false); 22}); 23 24function time(){ 25 var now = new Date(); 26 document.getElementById("time").innerHTML = now.toLocaleTimeString(); 27} 28 ons.ready(function() { 29 console.log("Onsen UI is ready!"); 30 }); 31 32 window.fn = {}; 33 window.fn.open = function() { 34 var menu = document.getElementById('menu'); 35 menu.open(); 36 }; 37 window.fn.load = function(page) { 38 var content = document.getElementById('content'); 39 var menu = document.getElementById('menu'); 40 content 41 .load(page) 42 .then(menu.close.bind(menu)); 43 }; 44 45 if (ons.platform.isIPhoneX()) { 46 document.documentElement.setAttribute('onsflag-iphonex-portrait', ''); 47 document.documentElement.setAttribute('onsflag-iphonex-landscape', ''); 48 } 49 </script> 50</head> 51<body> 52 <ons-splitter> 53 <ons-splitter-side id="menu" side="left" width="220px" collapse swipeable> 54 <ons-page> 55 <ons-list> 56 <ons-list-item onclick="fn.load('home.html')" tappable> 57 <h5><i style="float: left;"class="material-icons blue">home</i>Home</h5> 58 </ons-list-item> 59 <ons-list-item onclick="fn.load('settings.html')" tappable> 60 <h5><i style="float: left;"class="material-icons blue">settings</i>Settings</h5> 61 </ons-list-item> 62 <ons-list-item onclick="fn.load('about.html')" tappable> 63 <h5><i style="float: left;"class="material-icons blue">pie_chart</i>Chart</h5> 64 </ons-list-item> 65 <ons-list-item onclick="fn.load('about.html')" tappable> 66 <h5><i style="float: left;"class="material-icons blue">help_outline</i>How To</h5> 67 </ons-list-item> 68 </ons-list> 69 </ons-page> 70 </ons-splitter-side> 71 <ons-splitter-content id="content" page="home.html"></ons-splitter-content> 72 </ons-splitter> 73 74 <ons-template id="home.html"> 75 <ons-page> 76 <ons-toolbar-button onclick="fn.open()"> 77 <i style="float: left;"class="material-icons bigblue">reorder</i> 78 </ons-toolbar-button> 79 <i style="float: right;"class="material-icons bigblue">help_outline</i> 80 <h1 id="time"></h1> 81 </ons-page> 82 </ons-template> 83 84 <ons-template id="settings.html"> 85 <ons-page> 86 <ons-toolbar> 87 <div class="left"> 88 <ons-toolbar-button onclick="fn.open()"> 89 <ons-icon icon="ion-navicon, material:md-menu"></ons-icon> 90 </ons-toolbar-button> 91 </div> 92 <div class="center"> 93 Settings 94 </div> 95 </ons-toolbar> 96 </ons-page> 97 </ons-template> 98 99 <ons-template id="about.html"> 100 <ons-page> 101 <ons-toolbar> 102 <div class="left"> 103 <ons-toolbar-button onclick="fn.open()"> 104 <ons-icon icon="ion-navicon, material:md-menu"></ons-icon> 105 </ons-toolbar-button> 106 </div> 107 <div class="center"> 108 About 109 </div> 110 </ons-toolbar> 111 </ons-page> 112 </ons-template> 113 114</body> 115</html> 116
上記の状態で右と左にアイコンが並ぶのですが、その間に
html
1<h1 id="time"></h1>
を挟みたいのですが、
html
1 <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> 2<div class="f-container"> 3 <div class="f-item"><ons-toolbar-button onclick="fn.open()"> 4 <i style="float: left;"class="material-icons bigblue">reorder</i> 5 </ons-toolbar-button></div> 6 <div class="f-item"><h1 id="time">a</h1></div> 7 <div class="f-item"><i style="float: right;"class="material-icons bigblue">help_outline</i></div> 8</div>
上記のコードと
css
1.f-container { 2 display:flex; 3 flex-diretion: row; 4}
js
1ons.ready(function(){ 2 document.addEventListener('init', function(event) { 3 time(); 4 setInterval(time,1000); 5 }, false); 6}); 7 8function time(){ 9 var now = new Date(); 10 document.getElementById("time").innerHTML = now.toLocaleTimeString(); 11}
とcodepenにかいたのですが、見ればわかるとおりまず時間が表示されないのと、<h1></h1>の中だけ少し低くなってしまいます。これを直すにはどうすればいいでしょうか。
Monacaで動かすのを前提でお願いします。
回答1件
あなたの回答
tips
プレビュー