Create a single HTML file containing CSS and JavaScript to generate an animated weather card with detailed weather information. The card should visually represent the following weather conditions with distinct animations: Wind: (e.g., moving clouds, swaying trees, or wind lines) Rain: (e.g., falling raindrops, puddles forming) Sun: (e.g., shining rays, bright background) Snow: (e.g., falling snowflakes, snow accumulating) Show all the weather card side by side The card should have a dark background. Provide all the HTML, CSS, and JavaScript code within this single file. The JavaScript should include a way to switch between the different weather conditions (e.g., a function or a set of buttons) to demonstrate the animations for each.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
A div class="controls" containing buttons. Each button calls the setWeather() JavaScript function with a specific condition ('sun', 'wind', 'rain', 'snow', or 'none').
A div class="weather-cards-container" uses Flexbox (via CSS) to arrange the cards side-by-side.
Four div class="weather-card" elements, one for each weather type. Each has a unique id (card-sun, card-wind, etc.) for easy targeting by JavaScript.
Inside each card:
An <h2> for the condition name.
A div class="animation-area": This is where the animated elements are placed. It has a fixed height and position: relative so elements inside can be positioned absolutely.
Static HTML elements for the animations (div class="sun", div class="cloud", div class="raindrop", div class="snowflake"). There are multiple elements for rain, snow, and clouds to create a denser effect.
A div class="weather-details" with placeholder <p> tags for temperature, humidity, etc.
CSS (<style>):
General Styling: Sets up the dark page background, basic font, and centers content.
Controls: Styles the buttons.
Container: Uses display: flex, justify-content: center, and gap to arrange the cards nicely. flex-wrap: wrap allows cards to stack on smaller screens if needed.
.weather-card: Defines the appearance of each card (dark background, padding, border-radius, size, shadow, etc.). overflow: hidden is important to clip animations that go outside the bounds. position: relative is set for positioning context.
.animation-area: Styles the dedicated animation space within the card. position: relative and overflow: hidden are key here.
Animation Elements:
Styles the basic appearance of .sun, .ray, .cloud, , . They start with and .
This setup creates a visually appealing demonstration where each card represents a different potential weather state, and the buttons allow you to activate the specific animation on the corresponding card.
Uses pseudo-elements (::before, ::after) to create the fluffy cloud shape.
Positions elements using top, left, transform.
@keyframes: Defines the animations:
pulse: For the sun (scaling and shadow).
spin: Optional spinning for sun rays.
moveCloud: Moves clouds horizontally across the area.
fall: Basic vertical falling animation for rain.
fallSnow / fallSnow2: Falling animation for snow, including a slight horizontal drift and rotation.
Active States (.condition-active):
Crucially, the animations are not applied by default.
CSS rules like .weather-card.sun-active .sun, .weather-card.wind-active .cloud, etc., are used.
When the JavaScript adds a class like sun-active to the weather-card div, these CSS rules become active, setting opacity: 1 on the relevant elements and applying the animation property.
Different background gradients are applied to the .animation-area based on the active state for better visual distinction.
animation-delay and different animation-duration values are used heavily for rain and snow to make the effect look more natural and less uniform.
JavaScript (<script>):
setWeather(condition) function:
Takes the desired condition ('sun', 'wind', 'rain', 'snow', 'none') as an argument.
Selects all elements with the class weather-card.
Defines an array activeClasses holding all possible animation state classes.
It first loops through all cards and removes all active classes. This ensures that clicking a new button stops any previously running animation on any card.
If the condition is not 'none', it finds the specific card using document.getElementById('card-' + condition).
It adds the corresponding active class (e.g., sun-active) to only that specific card. This triggers the CSS rules for that card's animation.
If condition is 'none', no active classes are added, effectively stopping all animations.