最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序?qū)崿F(xiàn)天氣預(yù)報(bào)功能

 更新時(shí)間:2018年07月18日 17:13:52   作者:順子_RTFSC  
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)天氣預(yù)報(bào)功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)天氣預(yù)報(bào)功能的具體代碼,供大家參考,具體內(nèi)容如下

這個(gè)案例是仿UC中天氣界面做的中間也有點(diǎn)出入,預(yù)留了顯示當(dāng)前城市名字和刷新圖標(biāo)的位置,自己可以寫下,也可以添加搜索城市。值得注意的是100%這個(gè)設(shè)置好像已經(jīng)不好使了,可以通過獲取設(shè)備的高度通過數(shù)據(jù)綁定設(shè)置高度。地址:weather

界面主要分為四部分:

第一部分

這里是預(yù)留的一塊可以自行添加補(bǔ)充下

<view class="newTopView">
<!--左邊添加當(dāng)前城市名字,點(diǎn)擊跳轉(zhuǎn)選擇城市 右邊添加刷新當(dāng)前天氣-->
</view>

第二部分:

 <view class="topView">
 <view class="degreeView">
 <!--當(dāng)前溫度-->
 <text class="degree">{{currentTemperature}}</text>
 <!--度數(shù)圖標(biāo)-->
 <image class="circle" src="../../image/circle.png"></image>
 </view>
 <view class="detailInfo">
 <view class="degreeView">
 <!--夜間天氣情況-->
 <text class="detailInfoDegree">{{nightAirTemperature}}</text>
 <image class="detailInfoCircle" src="../../image/circle.png" />
 <text class="detailInfoLine">/</text>
 <!--白天天氣-->
 <text class="detailInfoDegree">{{dayAirTemperature}}</text>
 <!-- style優(yōu)先級比class高會(huì)覆蓋class中相同屬性 -->
 <image class="detailInfoCircle" style="margin-left: 57rpx; margin-right: 40rpx" src="../../image/circle.png" />
 <!-- 當(dāng)前天氣名字 -->
 <text class="detailInfoName">{{weather}}</text>
 </view>
 </view>
 </view>


第三部分:

 <!-- 中間部分 -->
 <view class="centerView">
 <view class="centerItem" style="margin-right: 25rpx;">
 <image class="centerItemImage" src="../../image/leaf.png" />
 <!-- 相同屬性抽出來! -->
 <!--污染指數(shù)-->
 <text class="centerItemText" style="margin-left: 10rpx; margin-right: 10rpx">{{aqi}}</text>
 <!--污染指數(shù)對應(yīng)name-->
 <text class="centerItemText">{{quality}}</text>
 </view>
 <view class="centerItem" style="margin-left: 25rpx">
 <image class="centerItemImage" src="../../image/wind.png" />
 <text class="centerItemText" style="margin-left: 10rpx; margin-right: 10rpx">{{windPower}}</text>
 <!--風(fēng)-->
 <text class="centerItemText">{{windDirection}}</text>
 </view>
 </view>

第四部分:

<!-- 底部view -->
 <view class="bottomView">
 <!--數(shù)據(jù)返回的不是數(shù)組 在js中拼接的數(shù)組-->
 <block wx:for-items="{{list}}">
 <view class="bottomItemView">
 <image class="bottomImage" src="{{item.day_weather_pic}}" style="margin-bottom: 15rpx;" />
 <text wx:if="{{item.weekday == 1}}" class="bottomText">星期一</text>
 <text wx:elif="{{item.weekday == 2}}" class="bottomText">星期二</text>
 <text wx:elif="{{item.weekday == 3}}" class="bottomText">星期三</text>
 <text wx:elif="{{item.weekday == 4}}" class="bottomText">星期四</text>
 <text wx:elif="{{item.weekday == 5}}" class="bottomText">星期五</text>
 <text wx:elif="{{item.weekday == 6}}" class="bottomText">星期六</text>
 <text wx:else="{{item.weekday == 7}}" class="bottomText">星期日</text>
 <view class="degreeView" style="margin-top: 20rpx;">
  <text class="detailInfoDegree">{{item.night_air_temperature}}</text>
  <image class="detailInfoCircle" src="../../image/circle.png" />
  <text class="detailInfoLine">/</text> 
  <text class="detailInfoDegree">{{item.day_air_temperature}}</text>
  <!-- style優(yōu)先級比class高會(huì)覆蓋class中相同屬性 -->
  <image class="detailInfoCircle" style="margin-left: 57rpx; margin-right: 40rpx" src="../../image/circle.png" />
 </view>
</view>

js

//index.js
//獲取應(yīng)用實(shí)例
var app = getApp()
Page({
 data: {
 //加載狀態(tài)
 loadingHidden: false,
 //當(dāng)前溫度
 currentTemperature: '',
 //夜間溫度
 nightAirTemperature: '',
 //白天溫度
 dayAirTemperature: '',
 //當(dāng)前天氣
 weather: '',
 //污染指數(shù)
 aqi: '',
 //污染程度
 quality: '',
 //風(fēng)力
 windPower: '',
 //風(fēng)向
 windDirection: '',
 //因?yàn)閿?shù)據(jù)返回不是數(shù)組所以要自己封裝一個(gè)數(shù)組
 list: [],
 height: 0,


 },

 onLoad: function () {
 console.log('onLoad')
 var that = this

 //100%好像不好使 可以獲取設(shè)備高度
 wx.getSystemInfo({
 success: function (res) {
 that.data.height = res.windowHeight;
 }
 })

 wx.getLocation({
 success: function (res) {
 //通過經(jīng)緯度請求數(shù)據(jù)
 wx.request({
  //這個(gè)網(wǎng)站有免費(fèi)API趕緊收藏
  url: 'http://route.showapi.com/9-5',
  data: {
  showapi_appid: '11697',
  showapi_sign: '6c0c15c5ec61454dac5288cea2d32881',
  //
  from: '5',
  lng: res.longitude,
  lat: res.latitude,
  //獲取一周情況 0是不獲取
  needMoreDay: '1',
  needIndex: '1'
  },
  success: function (res) {
  console.log(res)
  console.log(res.data.showapi_res_body.now.api)
  that.setData({
  //改變加載狀態(tài)
  loadingHidden: true,

  currentTemperature: res.data.showapi_res_body.now.temperature,
  nightAirTemperature: res.data.showapi_res_body.f1.night_air_temperature,
  dayAirTemperature: res.data.showapi_res_body.f1.day_air_temperature,
  weather: res.data.showapi_res_body.now.weather,
  aqi: res.data.showapi_res_body.now.aqi,
  quality: res.data.showapi_res_body.now.aqiDetail.quality,
  windPower: res.data.showapi_res_body.now.wind_power,
  windDirection: res.data.showapi_res_body.now.wind_direction,
  //拼接數(shù)組
  list: [
  {
   'day_weather_pic': res.data.showapi_res_body.f1.day_weather_pic,
   'weekday': res.data.showapi_res_body.f1.weekday,
   'day_air_temperature': res.data.showapi_res_body.f1.day_air_temperature,
   'night_air_temperature': res.data.showapi_res_body.f1.night_air_temperature
  },
  {
   'day_weather_pic': res.data.showapi_res_body.f2.day_weather_pic,
   'weekday': res.data.showapi_res_body.f2.weekday,
   'day_air_temperature': res.data.showapi_res_body.f2.day_air_temperature,
   'night_air_temperature': res.data.showapi_res_body.f2.night_air_temperature
  },
  {
   'day_weather_pic': res.data.showapi_res_body.f3.day_weather_pic,
   'weekday': res.data.showapi_res_body.f3.weekday,
   'day_air_temperature': res.data.showapi_res_body.f3.day_air_temperature,
   'night_air_temperature': res.data.showapi_res_body.f3.night_air_temperature
  },
  {
   'day_weather_pic': res.data.showapi_res_body.f4.day_weather_pic,
   'weekday': res.data.showapi_res_body.f4.weekday,
   'day_air_temperature': res.data.showapi_res_body.f4.day_air_temperature,
   'night_air_temperature': res.data.showapi_res_body.f4.night_air_temperature
  },
  {
   'day_weather_pic': res.data.showapi_res_body.f5.day_weather_pic,
   'weekday': res.data.showapi_res_body.f5.weekday,
   'day_air_temperature': res.data.showapi_res_body.f5.day_air_temperature,
   'night_air_temperature': res.data.showapi_res_body.f5.night_air_temperature
  },
  {
   'day_weather_pic': res.data.showapi_res_body.f6.day_weather_pic,
   'weekday': res.data.showapi_res_body.f6.weekday,
   'day_air_temperature': res.data.showapi_res_body.f6.day_air_temperature,
   'night_air_temperature': res.data.showapi_res_body.f6.night_air_temperature
  },
  {
   'day_weather_pic': res.data.showapi_res_body.f7.day_weather_pic,
   'weekday': res.data.showapi_res_body.f7.weekday,
   'day_air_temperature': res.data.showapi_res_body.f7.day_air_temperature,
   'night_air_temperature': res.data.showapi_res_body.f7.night_air_temperature
  }

  ]
  })
  }
 })

 }
 })

 }
})

wxss

.container {
 display: flex;
 flex-direction: column;
 justify-content: space-between;

}

.newTopView {
 display: flex;
 flex-direction: row;
 justify-content: space-between;
}

/* 頭部樣式上半部分*/
.topView {
 flex-direction: column;
 align-self: center;
 margin-top: -450rpx;
}
/*當(dāng)前度數(shù)樣式*/
.degreeView {
 flex-direction: row;
 position: relative;
}
/*當(dāng)前溫度度數(shù)圖標(biāo)*/
.circle {
 width: 35rpx;
 height: 35rpx; 
 position: absolute;
 left: 130rpx;
} 
/*當(dāng)前度數(shù)數(shù)組*/
.degree {
 color: white;
 font-size: 130rpx
}

/*詳細(xì)View樣式*/
.detailInfoView {
 flex-direction: row;
}
/*當(dāng)前最高和最低溫度度數(shù)圖標(biāo)*/
.detailInfoCircle {
 width: 20rpx;
 height: 20rpx; 
 position: absolute;
 left: 30rpx;
} 

/*當(dāng)前度數(shù)數(shù)組*/
.detailInfoDegree {
 color: white;
 font-size: 30rpx
}

/*斜線*/
.detailInfoLine {
 color: white;
 margin-left: 15rpx;
 font-size: 30rpx;
}
/*比如陰天 晴天,暴雨*/
.detailInfoName {
 font-size: 30rpx;
 color: white;
 margin-left: 20rpx;
 align-self: center
}

/*中間view樣式*/
.centerView {
 display: flex;
 flex-direction: row;
 margin-top: -550rpx;
 justify-content: center;
 align-items: center;
}

/*中間view分為兩個(gè)view*/
.centerItem {
 display: flex;
 flex-direction: row;
 align-items: center;
 justify-content: center;
}
/*Item中圖片樣式*/
.centerItemImage {
 width: 25rpx;
 height: 25rpx;
}
/*文字樣式*/
.centerItemText {
 font-size: 28rpx;
 color: white;
}

/*底部view樣式*/
.bottomView {
 margin-top: -200rpx;
 display: flex;
 flex-direction: row;
 justify-content: space-around;
 align-items: center;
}


.bottomItemView {
 display: flex;
 flex-direction: column;
 align-items: center;
 margin-bottom: 200rpx;
}

/*最近七天樣式*/
.bottomImage {
 width: 70rpx;
 height: 70rpx;
}

.bottomText {
 font-size: 28rpx;
 color: white;
}

PS:

開發(fā)者工具無法顯示問題:是因?yàn)閂iew沒有獲得高度,默認(rèn)個(gè)高度或者直接修改wxml中height高度即可。

另外,本站在線工具小程序上有一款天氣查詢工具,還添加了城市選擇的功能,感興趣的朋友可以掃描如下小程序碼查看:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 原生JS和jQuery操作DOM對比總結(jié)

    原生JS和jQuery操作DOM對比總結(jié)

    這篇文章主要給大家介紹了原生JS和jQuery操作DOM的一些對比總結(jié),文中總結(jié)了很多的對比,相信對大家的學(xué)習(xí)或者工作能帶來一定的幫助,需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-01-01
  • js實(shí)現(xiàn)仿百度瀑布流的方法

    js實(shí)現(xiàn)仿百度瀑布流的方法

    這篇文章主要介紹了js實(shí)現(xiàn)仿百度瀑布流的方法,以完整實(shí)例形式分析了js仿百度瀑布流的相關(guān)樣式與實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-02-02
  • js實(shí)現(xiàn)購物車商品數(shù)量加減

    js實(shí)現(xiàn)購物車商品數(shù)量加減

    這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)購物車商品數(shù)量加減,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • 十個(gè)開發(fā)人員面臨的最常見的JavaScript問題總結(jié)

    十個(gè)開發(fā)人員面臨的最常見的JavaScript問題總結(jié)

    今天,JavaScript?是幾乎所有現(xiàn)代?Web?應(yīng)用的核心。這就是為什么JavaScript問題,以及找到導(dǎo)致這些問題的錯(cuò)誤,是?Web?發(fā)者的首要任務(wù)。本文總結(jié)了十個(gè)常見的問題及解決方法,需要的可以參考一下
    2022-11-11
  • 原生js拖拽(第一課 未兼容)拖拽思路

    原生js拖拽(第一課 未兼容)拖拽思路

    第一步點(diǎn)擊需要拖動(dòng)的元素,在點(diǎn)擊下的元素被選中,進(jìn)行move移動(dòng),當(dāng)鼠標(biāo)彈起的時(shí)候,停止動(dòng)作.點(diǎn)擊元素oDIV的時(shí)候,可用的是oDIV區(qū)域,而move和up則是全局區(qū)域
    2013-03-03
  • 20個(gè)JS簡寫技巧提升工作效率

    20個(gè)JS簡寫技巧提升工作效率

    這篇文章主要介紹了20個(gè)JS簡寫技巧提升工作效率,本文特點(diǎn)以言簡意賅為主,圍繞JS簡寫技巧的話題展開全文,具有一定的查看價(jià)值 ,需要的小伙伴可以參考一下
    2021-12-12
  • javascript 進(jìn)度條 實(shí)現(xiàn)代碼

    javascript 進(jìn)度條 實(shí)現(xiàn)代碼

    這個(gè)例子是通過測試的。是真真正正根據(jù)記錄的條數(shù)掛鉤的。
    2009-07-07
  • javascript addLoadEvent函數(shù)說明

    javascript addLoadEvent函數(shù)說明

    網(wǎng)頁加載完整后會(huì)觸發(fā)一個(gè)onload事件,默認(rèn)地一個(gè)事件只能和一個(gè)函數(shù)綁定。
    2010-01-01
  • 解決JS中乘法的浮點(diǎn)錯(cuò)誤的方法

    解決JS中乘法的浮點(diǎn)錯(cuò)誤的方法

    本篇文章主要介紹了解決JS中乘法的浮點(diǎn)錯(cuò)誤的方法。需要的朋友可以過來參考下,希望對大家有所幫助
    2014-01-01
  • 前端獲取用戶地理定位的方法及一些注意事項(xiàng)

    前端獲取用戶地理定位的方法及一些注意事項(xiàng)

    這篇文章主要介紹了移動(dòng)端和PC端在使用定位過程中需要注意的事項(xiàng),包括系統(tǒng)GPS打開、定位權(quán)限、頁面授權(quán)等,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2025-02-02

最新評論

色达县| 长岛县| 固安县| 青田县| 常宁市| 法库县| 孝昌县| 沙湾县| 中西区| 兴仁县| 明光市| 新乡市| 聂拉木县| 湛江市| 怀安县| 宾阳县| 昌江| 沁水县| 新平| 乐平市| 西平县| 思南县| 集安市| 教育| 庄河市| 乌兰察布市| 乐东| 旬邑县| 城固县| 小金县| 防城港市| 夏邑县| 扎赉特旗| 罗田县| 托克托县| 黄陵县| 镇宁| 鱼台县| 扎赉特旗| 淅川县| 文山县|