简单版-本地天气

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>现在天气</title>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css" rel="stylesheet">
    <link rel="stylesheet" href="./css/style.css">
</head>
<body>
    <!-- https://s1.ax1x.com/2018/10/10/iY4xvq.jpg -->
    <div class="container-fluid">
        <div class="content">
            <div class="city">
                <div id="cityname">城市</div>
            </div>
            <div class="weather">天气</div>
            <div class="degree">
                <div class="tmp">30</div>
                <div class="tem-kind">°C</div>
            </div>
            <div class="wind">北风3级</div>
        </div>
    </div>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
<script src="./js/index.js"></script>
</html>
*{
    margin: 0;
    padding: 0;
}
body{
    overflow: none;
    background: url("https://s1.ax1x.com/2018/10/10/iY4xvq.jpg");
    background-size: cover;
}
.content{
    position: absolute;
    margin-top: 10%;
    margin-left: 20%;
    margin-right: 20%;
    width: 60%;
}
.city{
	text-align: center;
}
.city>div{
	font-size: 28px;
	vertical-align: middle;
	color: #2E94B9;
}
.weather{
	text-align: center;
	color: #2E94B9;
	font-size: 38px;
}
.degree{
	text-align: center;
	color: #2E94B9;
	font-size: 38px;
}
.degree div{
	display: inline;
}
.degree .tmp-kind{
	margin-left: 10px;
}
.degree .tmp-change{
	margin-left: 30px;
}
.wind{
	text-align: center;
	color: #2E94B9;
	font-size: 38px;
}
$(document).ready(function(){
    var lat , lon;
    
    if(navigator.geolocation){
        navigator.geolocation.getCurrentPosition(function (position) { 
            lat = position.coords.latitude;
            lon = position.coords.longitude;
            console.log(lat+" "+lon);

            var para = "https://free-api.heweather.com/s6/weather?location="+lon+","+lat+"&key=e9b54fa5486c4d709f80c608d2a170d1";
            console.log(para);

            $.getJSON(para , function (json) {
                var city= json["HeWeather6"][0]["basic"]["parent_city"];
                var area= json["HeWeather6"][0]["basic"]["admin_area"];
                var weatherNow = json["HeWeather6"][0]["now"]["cond_txt"];
                var degree = json["HeWeather6"][0]["now"]["tmp"];
                var windShow = json["HeWeather6"][0]["now"]["wind_dir"] + " " + json["HeWeather6"][0]["now"]["wind_spd"] + "级";
                console.log(windShow);

                $("#cityname").html(city+","+area);
	      		$('.weather').html(weatherNow);	
	      		$(".tmp").html(degree);
	      		$(".wind").html(windShow);
            });
         })
    }
});

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值