0

由于照顾生病的年迈父母,我已经有几年没能做网站设计了。现在我非常生疏,只是想不出来太多了。

在一个 div 中,我想根据季节有两张交替的图片(每 5 秒左右交替一次)。

如果是 Winter,则显示 winter01.png 和 winter02.jpg,交替显示。

我有以下用于根据季节更改 div 背景的工作代码,但弄清楚如何根据季节使内容交替显示两张图片远远超出了我的能力范围。

有什么帮助吗?我愿意发送一小笔 Paypal 捐款......

这是根据季节更改背景图像的代码:

<div class="homeBox">
<!--set background image according to season-->
<script type="text/JavaScript">
var north = true;
var today = new Date();
var month = today.getMonth();
if (today.getDate() > 20) month++;
var backImg = ['/windsong/images/seasonal/backgrounds/summer.jpg','/windsong/images/seasonal/backgrounds/autumn.jpg','/windsong/images/seasonal/backgrounds/winter.jpg','/windsong/images/seasonal/backgrounds/spring.jpg'];

document.getElementsByClassName('homeBox')[0].style.backgroundImage = 'url('+backImg[Math.floor((month+(north?6:0))/3)%4]+')'; `

4

1 回答 1

0

自己想出来的。将 Cycle2 与我找到的 PHP 脚本结合使用。

<!--slideshow-->
<div class="cycle-slideshow">

<?php

function current_season() {
       // Locate the icons
       $icons = array(
               "spring" => "images/seasonal/spring",
               "summer" => "images/seasonal/summer",
               "autumn" => "images/seasonal/autumn",
               "winter" => "images/seasonal/winter"
       );

       // What is today's date - number
       $day = date("z");

       //  Days of spring
       $spring_starts = date("z", strtotime("March 21"));
       $spring_ends   = date("z", strtotime("June 20"));

       //  Days of summer
       $summer_starts = date("z", strtotime("June 21"));
       $summer_ends   = date("z", strtotime("September 22"));

       //  Days of autumn
       $autumn_starts = date("z", strtotime("September 23"));
       $autumn_ends   = date("z", strtotime("December 20"));

       //  If $day is between the days of spring, summer, autumn, and winter
       if( $day >= $spring_starts && $day <= $spring_ends ) :
               $season = "spring";
       elseif( $day >= $summer_starts && $day <= $summer_ends ) :
               $season = "summer";
       elseif( $day >= $autumn_starts && $day <= $autumn_ends ) :
               $season = "autumn";
       else :
               $season = "winter";
       endif;

       $image_path = $icons[$season];

       echo $image_path;
}

?>

<img src="<?php current_season() ?>01.png" alt="" />
<img src="<?php current_season() ?>02.png" alt="" />

</div><!--end slideshow-->
于 2018-01-03T18:32:42.390 回答