ajax获取简单天气信息,jQuery 简单的天气查询服务
JavaScript
語言:
JaveScriptBabelCoffeeScript
確定
/
// NOTIFICATION SETTINGS, DONT TOUCH BELLOW //
///
function notificate(titlenotification,body,icon) {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check if the user is okay to get some notification
else if (Notification.permission === "granted") {
var title;
var content;
title=titlenotification;
content={
body:body,
icon:icon,
};
// If it's okay let's create a notification
var notification = new Notification(title,content);
}
// Otherwise, we need to ask the user for permission
// Note, Chrome does not implement the permission static property
// So we have to check for NOT 'denied' instead of 'default'
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// Whatever the user answers, we make sure we store the information
if(!('permission' in Notification)) {
Notification.permission = permission;
}
// If the user is okay, let's create a notification
if (permission === "granted") {
var notification = new Notification(title,content);
}
});
}
/
// NOTIFICATION SETTINGS, DONT TOUCH BELLOW //
///
// At last, if the user already denied any notification, and you
// want to be respectful there is no need to bother him any more.
}
notificate("Bem vindo","Estas s?o as primeiras configura??es do voice","");
// Docs at http://simpleweatherjs.com
/* Does your browser support geolocation? */
if ("geolocation" in navigator) {
$('.js-geolocation').show();
} else {
$('.js-geolocation').hide();
}
/* Where in the world are you? */
$(document).on('ready', function() {
navigator.geolocation.getCurrentPosition(function(position) {
loadWeather(position.coords.latitude+','+position.coords.longitude); //load weather using your lat/lng coordinates
});
});
/*
* Test Locations
* Austin lat/long: 30.2676,-97.74298
* Austin WOEID: 2357536
*/
function loadWeather(location, woeid) {
$.simpleWeather({
location: location,
woeid: woeid,
unit: 'c',
success: function(weather) {
html = '
'+weather.temp+'°'+weather.units.temp+'
';html += '
- '+weather.city+', '+weather.region+'';
html += '
'+weather.currently+'';html += '
'+weather.temp+'°C';$("#weather").html(html);
},
error: function(error) {
$("#weather").html('
'+error+'
');}
});
}
function speak(mensagem){
var msg = new SpeechSynthesisUtterance(mensagem);
window.speechSynthesis.speak(msg);
}
//Javascript
if (annyang) {
// Let's define a command.
var commands = {
'hello': function() { speak("Hello, what's your name?"); notificate("Bem vindo ao voice","test","")},
//fala do nome
'meu nome é :nome': function(e) { speak("Your name is"+e+""+"Ok"+e+"I go configurate yours preferences ok?"); notificate("Olá "+ e + " bem vindo","Vamos ver oque você gosta para exibir nos cards" ) },
'sistema idiota': function() { speak("Idiot is you .You speak with a computer. "); notificate("Idiota é você.","Quem é que fica falando com um computador hein?","") },
você n?o presta
'você n?o presta': function() { speak("You dont presta.You speak with a computer. "); notificate("Quem n?o presta é você","Folgado e vagabundo que tem pregui?a de fazer tudo seu vagabundo.","") },
///fun??o do asno ashuaashuaashuaashuaashua
'você é mais burro do que eu': function() { speak("Asno are you.Pelow menows i can speak english "); notificate("Cláro, né o que fala com o computador","Pra CER mais burro do que você é difícil, más agente faz o possível.","") },
'abrir google': function() { speak("Open you.You are very very folgueidw "); notificate("Para de falar comigo e faz alguma coisa","Agora o burro n?o sabe nem ao menos usar o mouse?","") },
//sim confirma o nome
'olá': function() { speak("Hello, what you want?") },
'quem foi :pessoa': function(pessoa) { },
'que horas s?o ': function() { speak("Agora s?o " + data.getHours() +"horas e " + data.getMinutes()+ "minutos" ) },
'qual é a temperatura em :nomedacidade': function(nomedacidade) {
$.simpleWeather({
location: nomedacidade,
woeid: '',
unit: 'c',
success: function(weather) {
speak("In "+ nomedacidade + "the weather in "+ weather.city + weather.region + "is"+ weather.temp + "degree celsius and currently is " + weather.currently);notificate("Temperatura","Agora em " + nomedacidade + weather.region + " está " + weather.temp + "°C","");
},
error: function(error) {
speak("Have a error.Try again later.");
}
});
},
};
// Add our commands to annyang
annyang.addCommands(commands);
// Start listening.
annyang.setLanguage("pt-BR");
annyang.start({ autoRestart: true });
}
//
// Docs at http://simpleweatherjs.com
/* Does your browser support geolocation? */
// //
// PAGE SETTINGS BELLOW //
// //
$(document).ready( function() {
$('.note').click( function() {
var el = $(this);
if( el.parent().hasClass('double') ) {
el = $(this).parent();
}
el.addClass('tr');
setTimeout( function() {
el.slideUp('100');
}, 400);
setTimeout( function() {
el.remove();
}, 500);
var test = $('#notes').children().size();
if(test == 2) {
setTimeout( function() {
$('#no-cards').css("display","block").slideDown();
}, 650);
}
});
});
總結
以上是生活随笔為你收集整理的ajax获取简单天气信息,jQuery 简单的天气查询服务的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Windows 服务器使用FTP出现“当
- 下一篇: css特效实现透明渐变