Skip to content

Commit

Permalink
重构代码
Browse files Browse the repository at this point in the history
  • Loading branch information
mouse-lin committed Apr 26, 2012
1 parent 51a21f6 commit 903f987
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
21 changes: 5 additions & 16 deletions index.html
Expand Up @@ -77,33 +77,22 @@ <h1>&</h1>
//User: Mouse
//Comment: load menu等html文件, 并且判断时间显示出页面
//date: 2012-04-23
var date = new Date();
var hour = date.getHours();
var sunHour = [6,7,8,9,10,11,12,13,14,15,16,17,18];
var dayTime = "night";
if($.inArray(hour,sunHour) != -1 ){
dayTime = "sun";
$("#day_change").html("黑夜");
}else{
$("#day_change").html("白天");
};
var weather = $("#weather");
var weatherHtmlFile = dayTime == "sun"? "sun.html" : "night.html";
weather.load(weatherHtmlFile);
timeInit();
Weather.weather.load(Weather.weatherHtmlFile);
$("#photo-show").load("photo_show.html");
$("#menu").load("menu.html");
$("#foot").load("foot.html");
$("#below_content").load("below_content.html");

$(document).ready(function(){
hideActionInit();
weatherChangeInit(dayTime,weather,weatherHtmlFile);
start(dayTime); // 启动天气效果;
weatherChangeInit(Weather.dayTime,Weather.weather,Weather.weatherHtmlFile);
start(Weather.dayTime); // 启动天气效果;
backToTop(); //back to top 按钮;
photoShowInit(); //照片展示
});
</script>
<!-- js 效果实现end -->

<p id="back-top"><a href="#top"><span></span><em>回到顶部</em> </a></p>
<div id="board-line"><img src="images/BoardLine.png"/></div>
</body>
Expand Down
16 changes: 16 additions & 0 deletions javascripts/init.js
@@ -1,6 +1,22 @@
//---------------------------------------------
// 用于初始化所有的函数, 这里的函数将直接在html页面调用

// 时间判断初始化
function timeInit(){
var date = new Date();
var hour = date.getHours();
var sunHour = [6,7,8,9,10,11,12,13,14,15,16,17,18];
Weather.dayTime = "night";
if($.inArray(hour,sunHour) != -1 ){
Weather.dayTime = "sun";
$("#day_change").html("黑夜");
}else{
$("#day_change").html("白天");
};
Weather.weather = $("#weather");
Weather.weatherHtmlFile = Weather.dayTime == "sun"? "sun.html" : "night.html";
}

//back-to-top
function backToTop(){
$("#back-top").hide();
Expand Down
10 changes: 8 additions & 2 deletions javascripts/weather.js
@@ -1,3 +1,9 @@
// 提供全局weather对象:
// weather: div对象
// weatherHtmlFile: html file
// dayTime: 时间 "sun" or "night"
Weather = { };

//白天云朵移动效果
function cloudMoveLeft(cloud){
cloud.animate({ left: "+=30" },4000,function(){
Expand Down Expand Up @@ -32,8 +38,8 @@ function start(dayTime){
var elSunRays = $('#sun-rays');
var sunFace = $('#sun-face');
var sunRotation = 0;
//cloudMoveRight(cloudRed);
//cloudMoveLeft(cloudGreen);
cloudMoveRight(cloudRed);
cloudMoveLeft(cloudGreen);
setInterval(function() {
if (elSunRays) {
sunRotation ++;
Expand Down

0 comments on commit 903f987

Please sign in to comment.