起動するとアイコンが表示され、アイコンを押下すると、ロゴ画面に遷移し、2秒立つとカメラが起動するアプリを作りたいです。
しかし、私のコードだと、アプリを起動するとアイコンが表示され、何もしなくても一瞬でカメラが起動してしまいます。
3つ目のコードの'device ready'と記述してあるところがいけないと思うのですが、
正しい書き方がわかりません
どうすれば良いのでしょうか?
わかる方助けてください
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> <title> LIVE </title> <script> function imgClick() { //指定したURLやファイルに遷移させる。 window.location.href="logo.html"; } </script> <!--クリックすると、imaClick関数の呼び出し--> <a href="javascript:void(0)" onclick="imgClick();"> <img src="img/Icon.png" width="100" height="100" /></a> <!--cordova.jsの読み込み--> <!--divは囲んだ範囲を1つのかたまりとして、align属性で位置を指定したりできる。--> <div class="app"> <div id="deviceready" class="blink"> <p class="event listening"></p> <p class="event received"></p> </div> </div> <script type="text/javascript" src="cordova.js"></script> <script type="text/javascript" src="js/index.js"></script> </head> </html>
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> <title> LIVE </title> <img src="img/Icon.png" width="350" height="600" ; /> <script type="text/javascript" src="/js/index.js"></script> </head> </html>
/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ var app = { // コンストラクタ initialize: function() { this.bindEvents(); }, // Bind Event Listeners // // // 'deviceready'はCordovaを全て読み込んでから bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); }, // deviceready Event Handler // // The scope of 'this' is the event. In order to call the 'receivedEvent' // function, we must explicitly call 'app.receivedEvent(...);' onDeviceReady: function() { app.receivedEvent('deviceready'); //カメラへのオプション var options = { quality: 50, destinationType: navigator.camera.DestinationType.FILE_URI }; //カメラを起動する。 navigator.camera.getPicture(function(imageData) { alert(imageData); }, function() { alert('fail'); }, options); //setTimeoutは第一引数に呼び出したい関数、第二引数に待機時間を設定する。2000=2秒 //setTimeoutのTは大文字でなければ実行されない。 setTimeout(nabigator,2000); }, // Update DOM on a Received Event receivedEvent: function(id) { var parentElement = document.getElementById(id); var listeningElement = parentElement.querySelector('.listening'); var receivedElement = parentElement.querySelector('.received'); listeningElement.setAttribute('style', 'display:none;'); receivedElement.setAttribute('style', 'display:block;'); console.log('Received Event: ' + id); } }; app.initialize();
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/24 02:31
2016/10/24 02:42