You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
129 lines
5.3 KiB
JavaScript
129 lines
5.3 KiB
JavaScript
6 years ago
|
$(function(){
|
||
|
|
||
|
$.ajax({
|
||
|
type: "GET",
|
||
|
url: "/api/weather2.php?city="+City,
|
||
|
success: function(Data){
|
||
|
//------------------------------------------------------------------------------
|
||
|
|
||
|
Data = eval("("+Data+")");
|
||
|
var weater_tmp = "";
|
||
|
weater_tmp +=" <div class=\"weader col-md-8 col-sm-8 col-xs--24\"> ";
|
||
|
weater_tmp +=" <img src=\"http:\/\/data.chinahighlights.com/css/images/citytour/"+weather_bg+"\" class=\"img-responsive\" /> ";
|
||
|
weater_tmp +=" <div class=\"weader-tobday\"> </div> ";
|
||
|
weater_tmp +=" <div class=\"weaderbar\"> ";
|
||
|
weater_tmp +=" <ul> ";
|
||
|
weater_tmp +=" <li></li> ";
|
||
|
weater_tmp +=" <li class=\"wind\"><img src=\"http:\/\/data.chinahighlights.com/css/images/citytour/weathtemp.png\" /><br /><span class=\"sleep\"></span></li> ";
|
||
|
weater_tmp +=" <li align=\"left\"><img src=\"http:\/\/data.chinahighlights.com/css/images/weater-icons/Sunny.gif\" /></li> ";
|
||
|
weater_tmp +=" </ul> ";
|
||
|
weater_tmp +=" </div> ";
|
||
|
weater_tmp +=" </div> ";
|
||
|
weater_tmp +=" <div class=\"weadercont col-md-16 col-sm-16 hidden-xs\"> ";
|
||
|
weater_tmp +=" </div> ";
|
||
|
if ( Data == 404) {
|
||
|
|
||
|
}else {
|
||
|
$(".cityweather").append(weater_tmp);
|
||
|
if ( Data.General.Name[0].toLowerCase().replace(/(\s+|\'+|\/+|,+)/gi, '-').replace(/(\-+)/gi, '-') == City.toLowerCase() ) {
|
||
|
|
||
|
var today_dom = $(".cityweather .weader .weaderbar ul li");
|
||
|
//Data.General[0].Forecast[0].Date
|
||
|
var ___today = Data.General.Forecast[0].Date.Date.split("/");
|
||
|
var today = new Date(___today[1]+'/'+___today[0]+'/'+___today[2]);
|
||
|
var today_arr = today.toString().split(' ');
|
||
|
$(".cityweather .weader-tobday").html(today_arr[1]+' '+parseInt(today_arr[2], 10)); //
|
||
|
var NightMin = isUndefined(Data.General.Forecast[0].Night) === true ? '' : Data.General.Forecast[0].Night.NightMin ;
|
||
|
today_dom.eq(0).html("Max "+ Data.General.Forecast[0].Day.DayMax +"°C<br />Min "+ NightMin +"°C");
|
||
|
today_dom.eq(1).find("img").eq(0).attr("src", "http:\/\/data.chinahighlights.com/css/images/weater-icons/WindIcons/"+Data.General.Forecast[0].Day.WindDir+".gif");
|
||
|
//console.log(today_dom.eq(1).find("img").eq(0).attr("src", "/css/images/weater-icons/"+Data.General.Forecast[0].Day.WindDir+""));
|
||
|
today_dom.eq(1).find(".sleep").html(getWindSpeed(Data.General.Forecast[0].Day.WindSpeed_kph, Data.General.Forecast[0].Night.WindSpeed_kph) + ' km/h');
|
||
|
today_dom.eq(2).find("img").attr("src", "http:\/\/data.chinahighlights.com/css/images/weater-icons/" + getOverheadIcon(
|
||
|
Data.General.Forecast[0].Day.OverheadIcon,
|
||
|
Data.General.Forecast[0].Night.OverheadIcon
|
||
|
));
|
||
|
var si = 0;
|
||
|
for(var i = 1; i < Data.General.Forecast.length; i++){
|
||
|
if(si>= 7) break;
|
||
|
//<img src="/css/images/citytour/weathtemp.png" />
|
||
|
var ___mday = Data.General.Forecast[i].Date.Date.split("/");
|
||
|
var mday = new Date(___mday[1]+'/'+___mday[0]+'/'+___mday[2]);
|
||
|
var utc8 = bjtime();
|
||
|
if(mday >= utc8){
|
||
|
si++;
|
||
|
var mday_arr = mday.toString().split(' ');
|
||
|
var item = "";
|
||
|
item += '<ul>';
|
||
|
item += ' <li class="wdate">'+(mday_arr[0]+' '+parseInt(mday_arr[2], 10))+'</li>';
|
||
|
item += ' <li>'+( "Max "+ Data.General.Forecast[i].Day.DayMax +"°C<br />Min "+ (
|
||
|
Data.General.Forecast[i].Night == undefined ? 0 : Data.General.Forecast[i].Night.NightMin
|
||
|
) +"°C" )+'</li>';
|
||
|
item += ' <li><img src="'+"http:\/\/data.chinahighlights.com/css/images/weater-icons/WindIcons/"+Data.General.Forecast[i].Day.WindDir+".gif"+'" /> '+(
|
||
|
getWindSpeed(Data.General.Forecast[i].Day.WindSpeed_kph,
|
||
|
(Data.General.Forecast[i].Night == undefined ? 0 : Data.General.Forecast[i].Night.WindSpeed_kph)
|
||
|
) + ' km/h' || '')+'</li>';
|
||
|
item += ' <li>'+(
|
||
|
'<img src="http:\/\/data.chinahighlights.com/css/images/weater-icons/' + getOverheadIcon(
|
||
|
Data.General.Forecast[i].Day.OverheadIcon,
|
||
|
(Data.General.Forecast[i].Night == undefined ? 0 : Data.General.Forecast[i].Night.OverheadIcon)
|
||
|
) + '" />'
|
||
|
)+'</li>';
|
||
|
item += '</ul>';
|
||
|
$(".weadercont").append(item);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
$(".cityweather").show();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
//------------------------------------------------------------------------------
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
|
||
|
function getWindSpeed(day, night){
|
||
|
var day = parseInt(day, 10);
|
||
|
var night = parseInt(night, 10);
|
||
|
if(day > night){
|
||
|
return night+'-'+day;
|
||
|
}else if(day < night){
|
||
|
return day+'-'+night;
|
||
|
}else{
|
||
|
return day;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function getOverheadIcon(day, night){
|
||
|
if(Now.getHours() < 18 ) {
|
||
|
return day;
|
||
|
}else{
|
||
|
return night;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
function isEmptyOther(obj, fuc, oth){
|
||
|
return (fuc in obj) == true ? obj[fuc]: oth;
|
||
|
}*/
|
||
|
|
||
|
function isUndefined(para) {
|
||
|
if (typeof para == 'undefined') {
|
||
|
return true;
|
||
|
}else{
|
||
|
return false
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function bjtime(){
|
||
|
var d = new Date();
|
||
|
var localTime = d.getTime();
|
||
|
var localOffset = d.getTimezoneOffset() * 60000;
|
||
|
var utc = localTime + localOffset; //得到国际标准时间
|
||
|
var offset = 8;
|
||
|
var calctime = utc + (3600000*offset);
|
||
|
var nd = new Date(calctime);
|
||
|
return new Date(nd.getFullYear(),nd.getMonth(),nd.getDate());
|
||
|
//document.write('指定时区时间是:' + nd.toString());
|
||
|
}
|