何よりもまず、私はjavascript/jqueryを知りません...まだ学ぼうとしています。現在、SimpleWeather.js を使用して Web ページに天気を表示するプロジェクトに取り組んでいます。ただし、結果 (場所、気温、最高/最低など) をページの別の場所に表示したいと考えています。たとえば、場所をウィンドウの左上に表示し、現在の温度を左中央に別々の div で表示したいとします。残念ながら、結果を分離することはできないようです。それらはすべて一緒にロードされ、個別の div に配置することはできません。
私のページは次のように設定されています。
<body>
<div id="container">
<div id="top-header">
<h1 id="display-location">Location Here...</h1>
</div>
</div>
<div id="main-body">
<div id="current-weather-column">
<h2>Current weather is gonna go here.</h2>
</div>
</div>
<div id="four-day-forecast-area" class="three-col">
<h2>Rest of forecast/four-day forecast here...</h2>
</div>
<script>
// Docs at http://simpleweatherjs.com
$(document).ready(function() {
$.simpleWeather({
zipcode: '60605',
woeid: '', //2357536
location: '',
unit: 'f',
success: function(weather) {
if(weather.temp > 75) {
$('body').animate({backgroundColor: '#F7AC57'}, 1500);
} else {
$('body').animate({backgroundColor: '#0091c2'}, 1500);
}
html = '<h1 class="icon-'+weather.code+'"></h1>';
html += '<h2 class="weather-temp">'+weather.temp+'°</h2>';
html += '<ul><li>'+weather.city+', '+weather.region+'</li>';
html += '<li class="currently">'+weather.currently+'</li></ul>';
//html += '<li>'+weather.tempAlt+'°C</li></ul>';
var timestamp = moment(weather.updated);
html += '<p class="updated">Updated '+moment(timestamp).fromNow()+'</p>';
$("#weather").html(html);
},
error: function(error) {
$("#weather").html('<p>'+error+'</p>');
}
});
});
<!-- I then list the rest of the script which is fairly long. If needed, you can take a look at http://simpleweatherjs.com -->
</body>
うまくいけば、それは理にかなっています。皆さんが与えることができるどんな助けも、私にとって大きな意味があります。ありがとうございました!