一个简单的jQuery插件可以显示当前的天气信息,使用雅虎天气的任何位置。开发者James Fleeting。下载最新的版本,阅读文档或浏览常见问题解答simpleweather.js。下面你会发现使用simpleWeather.js的一个例子。
只需在您的网站jquery.simpleWeather.js。然后初始化simpleWeather,设置您的WOEID,美国邮递区号或位置,添加一个div与``天气的ID(或任何你想要的,只是改变它在init)。
html
1 | <div id="weather"></div> |
css
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | body { font: 13px 'Open Sans', "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; background: #0091c2;}#weather { width: 425px; margin: 0px auto; text-align: center; text-transform: uppercase;}#weather h2 { margin: 0 0 8px; color: #fff; font-size: 150px; font-weight: 300; text-align: center; text-shadow: 0px 1px 3px rgba(0, 0, 0, 0.15);}#weather ul { margin: 0; padding: 0;}#weather li { background: #fff; background: rgba(255,255,255,0.90); padding: 20px; display: inline-block; border-radius: 5px;}#weather .currently { margin: 0 20px;} |
js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | $(document).ready(function() { $.simpleWeather({ zipcode: '', woeid: '2357536', location: '', unit: 'f', success: function(weather) { html = '<h2>'+weather.temp+'°'+weather.units.temp+'</h2>'; html += '<ul><li>'+weather.city+', '+weather.region+'</li>'; html += '<li class="currently">'+weather.currently+'</li>'; html += '<li>'+weather.tempAlt+'°C</li></ul>'; $("#weather").html(html); }, error: function(error) { $("#weather").html('<p>'+error+'</p>'); } });}); |
特别申明:
本站所有资源都是由网友投稿发布,或转载各大下载站,请自行检测软件的完整性!
本站所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!
如有侵权请联系我们删除下架,联系方式:lei1294551502@163.com