HTML+CSS+JS实现好看的风车屋

2024-03-26 03:40

本文主要是介绍HTML+CSS+JS实现好看的风车屋,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

直接看效果:

首先背景和月亮就是单纯的css背景色渐变;

四个扇叶就是通过rotate旋转得到的,然后将扇叶容器div添加绕中心旋转的动画;

背后的星星随机定位生成,并添加闪烁动画,不同的星星添加随机的animation-delay时间;

流星也是一个位移动画而已;

房子的门加上box-shadow有灯光效果。

没啥难的,配色好看,整体效果就能好看了。

所有代码:

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8" /><meta http-equiv="X-UA-Compatible" content="IE=edge" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><!-- <link rel="stylesheet" type="text/css" href="index.css" /> --><style>body {padding: 0;margin: 0;background: #292f4c;}/* 圆圈窗口容器 */.circle-container {height: 340px;width: 340px;border: 10px solid #3b436d;border-radius: 50%;margin: 10% auto;position: relative;background: linear-gradient(to bottom,#4d4d83 0%,#c76961 246px,#292f4c 0%);overflow: hidden;}.moon {position: absolute;height: 112px;width: 112px;background: linear-gradient(to bottom, #ffc673 0%, #ff653c 100%);left: 36px;top: 70px;border-radius: 50%;}/* 星星 */.star {background: white;height: 2px;width: 2px;position: absolute;left: 100px;top: 20px;border-radius: 25%;opacity: 0.5;}@keyframes starOdd {10% {opacity: 0.3;}90% {opacity: 0.7;}}@keyframes starEven {10% {opacity: 0.1;}90% {opacity: 0.8;}}.star:nth-child(odd) {animation: starOdd 2.5s ease-in infinite;}.star:nth-child(even) {animation: starEven 2.5s ease-in infinite;}/* 树林 */.trees {bottom: -8px;position: absolute;}.tree {width: 0;height: 0;border-left: 12px solid transparent;border-right: 12px solid transparent;border-bottom: 48px solid #292f4c;position: absolute;bottom: 80px;}/* 房子 */.house {position: absolute;bottom: -10px;left: 122px;}.windmill {position: absolute;top: -250px;z-index: 8;left: -42px;animation: rotatemill 10s infinite linear;transform-origin: 89px 24px;}@keyframes rotatemill {100% {transform: rotate(360deg);}}.fan-wing {width: 89px;height: 16px;border-bottom: 8px solid #292f4c;position: relative;left: 0;left: 0;}.fan-1 {left: 0;}.fan-2 {transform: rotate(90deg);transform-origin: 102px 7px;}.fan-3 {transform: rotate(180deg);transform-origin: 90px -4px;}.fan-4 {transform: rotate(270deg);transform-origin: 52px -17px;}.fan-comb {width: 64px;height: inherit;border: 4px solid #292f4c;}.fan-comb > div {border-right: 4px solid #292f4c;display: inline;margin-left: 5.4px;}.roof {border-left: 48px solid transparent;border-right: 48px solid transparent;border-bottom: 48px solid #292f4c;position: absolute;width: 0;height: 0;bottom: 210px;left: 0px;}.floors {height: 110px;width: 74px;background: #292f4c;left: 12px;position: absolute;bottom: 100px;}.floors:before {position: absolute;content: "";width: 0;height: 0;border-left: 11px solid transparent;border-right: 0px solid transparent;border-bottom: 110px solid #292f4c;left: -11px;}.floors:after {position: absolute;content: "";width: 0;height: 0;border-left: 0px solid transparent;border-right: 11px solid transparent;border-bottom: 110px solid #292f4c;right: -11px;bottom: 0;}.light {height: 12px;width: 12px;background: linear-gradient(to bottom, #ffed60 0%, #ffb73c 100%);border-radius: 50%;position: absolute;top: 10px;left: 30px;}.light:before {content: "";height: 36px;width: 12px;background: linear-gradient(to bottom,#ffed6000 0%,#ffb73c 50%,#ffed6000 100%);position: absolute;top: -12px;opacity: 0.3;}.light:after {content: "";height: 36px;width: 12px;background: linear-gradient(to bottom,#ffed6000 0%,#ffb73c 50%,#ffed6000 100%);position: absolute;top: -12px;opacity: 0.3;transform: rotate(90deg);}.door {height: 32px;width: 24px;background: linear-gradient(to bottom, #ffed60 0%, #ffb73c 100%);border-radius: 12px 12px 0 0;position: absolute;bottom: 0;left: 25px;box-shadow: 0 0px 15px #ffed60;}/* 流星 */.shooting-star {transform: rotate(-45deg);margin: 30px;display: block;width: 0;border-radius: 2px;border-top-width: 1px;border-top-style: solid;border-top-color: transparent;border-left-width: 130px;border-left-style: solid;border-left-color: white;border-right-width: 130px;border-right-style: solid;border-right-color: transparent;border-bottom-width: 1px;border-bottom-style: solid;border-bottom-color: white;opacity: 0.7;}.animation {animation: fly 8s infinite;}@keyframes fly {from {transform: rotate(-45deg) translateX(900px);border-left-width: 130px;border-right-width: 130px;}to {transform: rotate(-45deg) translateX(-900px);border-left-width: 160px;border-right-width: 160px;}}</style><title>Windmill</title></head><body><div class="circle-container"><span class="shooting-star animation"></span><div id="stars" class="stars"></div><div class="moon"></div><div class="trees" id="trees"></div><div class="house"><div class="windmill" id="windmill"></div><div class="roof"></div><div class="floors"><div class="light"></div><div class="door"></div></div></div></div></body><script>function randomNum(minNum, maxNum) {switch (arguments.length) {case 1:return parseInt(Math.random() * minNum + 1, 10);break;case 2:return parseInt(Math.random() * (maxNum - minNum + 1) + minNum, 10);break;default:return 0;break;}}window.onload = () => {console.log("load");let fragment = document.createDocumentFragment();// 创建30颗星星for (let i = 0; i < 30; i++) {// 生成随机位置let child = document.createElement("div");child.className = "star star-" + (i + 1);child.style = `left:${randomNum(40, 300)}px;top:${randomNum(40,200)}px;`;child.style.setProperty("animation-duration", randomNum(2, 5) + "s");fragment.appendChild(child);}document.getElementById("stars").appendChild(fragment);// 生成treelet treePosition = [{left: 22,bottom: 0},{left: 42,bottom: 100},{left: 62,bottom: 90},{left: 74,bottom: 94},{left: 90,bottom: 102},{left: 120,bottom: 0},{left: 140,bottom: 0},{left: 160,bottom: 0},{left: 190,bottom: 0},{left: 205,bottom: 90},{left: 220,bottom: 100},{left: 240,bottom: 90},{left: 260,bottom: 100},{left: 280,bottom: 80}];let fragmentTree = document.createDocumentFragment();// 创建30颗星星for (let i = 0; i < 14; i++) {// 生成随机位置let child = document.createElement("div");child.className = "tree tree-" + (i + 1);child.style =`left:${treePosition[i].left}px;` +(treePosition[i].bottom > 0? `bottom:${treePosition[i].bottom}px;`: "");fragmentTree.appendChild(child);}document.getElementById("trees").appendChild(fragmentTree);};// 创建风车的四个扇叶let fragmentFan = document.createDocumentFragment();for (let i = 0; i < 4; i++) {// 生成随机位置let child = document.createElement("div");child.className = "fan-wing fan-" + (i + 1);let comb = document.createElement("div");comb.className = "fan-comb";for (let j = 0; j < 6; j++) {comb.appendChild(document.createElement("div"));}child.appendChild(comb);fragmentFan.appendChild(child);}document.getElementById("windmill").appendChild(fragmentFan);</script>
</html>

这篇关于HTML+CSS+JS实现好看的风车屋的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!


原文地址:https://blog.csdn.net/denglouhen/article/details/125205919
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.chinasem.cn/article/847178

相关文章

使用Python实现网页表格转换为markdown

《使用Python实现网页表格转换为markdown》在日常工作中,我们经常需要从网页上复制表格数据,并将其转换成Markdown格式,本文将使用Python编写一个网页表格转Markdown工具,需... 在日常工作中,我们经常需要从网页上复制表格数据,并将其转换成Markdown格式,以便在文档、邮件或

Python使用pynput模拟实现键盘自动输入工具

《Python使用pynput模拟实现键盘自动输入工具》在日常办公和软件开发中,我们经常需要处理大量重复的文本输入工作,所以本文就来和大家介绍一款使用Python的PyQt5库结合pynput键盘控制... 目录概述:当自动化遇上可视化功能全景图核心功能矩阵技术栈深度效果展示使用教程四步操作指南核心代码解析

SpringBoot实现文件记录日志及日志文件自动归档和压缩

《SpringBoot实现文件记录日志及日志文件自动归档和压缩》Logback是Java日志框架,通过Logger收集日志并经Appender输出至控制台、文件等,SpringBoot配置logbac... 目录1、什么是Logback2、SpringBoot实现文件记录日志,日志文件自动归档和压缩2.1、

Python实现pdf电子发票信息提取到excel表格

《Python实现pdf电子发票信息提取到excel表格》这篇文章主要为大家详细介绍了如何使用Python实现pdf电子发票信息提取并保存到excel表格,文中的示例代码讲解详细,感兴趣的小伙伴可以跟... 目录应用场景详细代码步骤总结优化应用场景电子发票信息提取系统主要应用于以下场景:企业财务部门:需

基于Python实现智能天气提醒助手

《基于Python实现智能天气提醒助手》这篇文章主要来和大家分享一个实用的Python天气提醒助手开发方案,这个工具可以方便地集成到青龙面板或其他调度框架中使用,有需要的小伙伴可以参考一下... 目录项目概述核心功能技术实现1. 天气API集成2. AI建议生成3. 消息推送环境配置使用方法完整代码项目特点

spring-gateway filters添加自定义过滤器实现流程分析(可插拔)

《spring-gatewayfilters添加自定义过滤器实现流程分析(可插拔)》:本文主要介绍spring-gatewayfilters添加自定义过滤器实现流程分析(可插拔),本文通过实例图... 目录需求背景需求拆解设计流程及作用域逻辑处理代码逻辑需求背景公司要求,通过公司网络代理访问的请求需要做请

使用Python获取JS加载的数据的多种实现方法

《使用Python获取JS加载的数据的多种实现方法》在当今的互联网时代,网页数据的动态加载已经成为一种常见的技术手段,许多现代网站通过JavaScript(JS)动态加载内容,这使得传统的静态网页爬取... 目录引言一、动态 网页与js加载数据的原理二、python爬取JS加载数据的方法(一)分析网络请求1

Spring Security介绍及配置实现代码

《SpringSecurity介绍及配置实现代码》SpringSecurity是一个功能强大的Java安全框架,它提供了全面的安全认证(Authentication)和授权(Authorizatio... 目录简介Spring Security配置配置实现代码简介Spring Security是一个功能强

SpringCloud使用Nacos 配置中心实现配置自动刷新功能使用

《SpringCloud使用Nacos配置中心实现配置自动刷新功能使用》SpringCloud项目中使用Nacos作为配置中心可以方便开发及运维人员随时查看配置信息,及配置共享,并且Nacos支持配... 目录前言一、Nacos中集中配置方式?二、使用步骤1.使用$Value 注解2.使用@Configur

Python+PyQt5实现MySQL数据库备份神器

《Python+PyQt5实现MySQL数据库备份神器》在数据库管理工作中,定期备份是确保数据安全的重要措施,本文将介绍如何使用Python+PyQt5开发一个高颜值,多功能的MySQL数据库备份工具... 目录概述功能特性核心功能矩阵特色功能界面展示主界面设计动态效果演示使用教程环境准备操作流程代码深度解