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实现好看的风车屋的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/847178

相关文章

Vue3 的 shallowRef 和 shallowReactive:优化性能

大家对 Vue3 的 ref 和 reactive 都很熟悉,那么对 shallowRef 和 shallowReactive 是否了解呢? 在编程和数据结构中,“shallow”(浅层)通常指对数据结构的最外层进行操作,而不递归地处理其内部或嵌套的数据。这种处理方式关注的是数据结构的第一层属性或元素,而忽略更深层次的嵌套内容。 1. 浅层与深层的对比 1.1 浅层(Shallow) 定义

JS常用组件收集

收集了一些平时遇到的前端比较优秀的组件,方便以后开发的时候查找!!! 函数工具: Lodash 页面固定: stickUp、jQuery.Pin 轮播: unslider、swiper 开关: switch 复选框: icheck 气泡: grumble 隐藏元素: Headroom

这15个Vue指令,让你的项目开发爽到爆

1. V-Hotkey 仓库地址: github.com/Dafrok/v-ho… Demo: 戳这里 https://dafrok.github.io/v-hotkey 安装: npm install --save v-hotkey 这个指令可以给组件绑定一个或多个快捷键。你想要通过按下 Escape 键后隐藏某个组件,按住 Control 和回车键再显示它吗?小菜一碟: <template

【 html+css 绚丽Loading 】000046 三才归元阵

前言:哈喽,大家好,今天给大家分享html+css 绚丽Loading!并提供具体代码帮助大家深入理解,彻底掌握!创作不易,如果能帮助到大家或者给大家一些灵感和启发,欢迎收藏+关注哦 💕 目录 📚一、效果📚二、信息💡1.简介:💡2.外观描述:💡3.使用方式:💡4.战斗方式:💡5.提升:💡6.传说: 📚三、源代码,上代码,可以直接复制使用🎥效果🗂️目录✍️

【前端学习】AntV G6-08 深入图形与图形分组、自定义节点、节点动画(下)

【课程链接】 AntV G6:深入图形与图形分组、自定义节点、节点动画(下)_哔哩哔哩_bilibili 本章十吾老师讲解了一个复杂的自定义节点中,应该怎样去计算和绘制图形,如何给一个图形制作不间断的动画,以及在鼠标事件之后产生动画。(有点难,需要好好理解) <!DOCTYPE html><html><head><meta charset="UTF-8"><title>06

hdu1043(八数码问题,广搜 + hash(实现状态压缩) )

利用康拓展开将一个排列映射成一个自然数,然后就变成了普通的广搜题。 #include<iostream>#include<algorithm>#include<string>#include<stack>#include<queue>#include<map>#include<stdio.h>#include<stdlib.h>#include<ctype.h>#inclu

【C++】_list常用方法解析及模拟实现

相信自己的力量,只要对自己始终保持信心,尽自己最大努力去完成任何事,就算事情最终结果是失败了,努力了也不留遗憾。💓💓💓 目录   ✨说在前面 🍋知识点一:什么是list? •🌰1.list的定义 •🌰2.list的基本特性 •🌰3.常用接口介绍 🍋知识点二:list常用接口 •🌰1.默认成员函数 🔥构造函数(⭐) 🔥析构函数 •🌰2.list对象

【Prometheus】PromQL向量匹配实现不同标签的向量数据进行运算

✨✨ 欢迎大家来到景天科技苑✨✨ 🎈🎈 养成好习惯,先赞后看哦~🎈🎈 🏆 作者简介:景天科技苑 🏆《头衔》:大厂架构师,华为云开发者社区专家博主,阿里云开发者社区专家博主,CSDN全栈领域优质创作者,掘金优秀博主,51CTO博客专家等。 🏆《博客》:Python全栈,前后端开发,小程序开发,人工智能,js逆向,App逆向,网络系统安全,数据分析,Django,fastapi

让树莓派智能语音助手实现定时提醒功能

最初的时候是想直接在rasa 的chatbot上实现,因为rasa本身是带有remindschedule模块的。不过经过一番折腾后,忽然发现,chatbot上实现的定时,语音助手不一定会有响应。因为,我目前语音助手的代码设置了长时间无应答会结束对话,这样一来,chatbot定时提醒的触发就不会被语音助手获悉。那怎么让语音助手也具有定时提醒功能呢? 我最后选择的方法是用threading.Time

Android实现任意版本设置默认的锁屏壁纸和桌面壁纸(两张壁纸可不一致)

客户有些需求需要设置默认壁纸和锁屏壁纸  在默认情况下 这两个壁纸是相同的  如果需要默认的锁屏壁纸和桌面壁纸不一样 需要额外修改 Android13实现 替换默认桌面壁纸: 将图片文件替换frameworks/base/core/res/res/drawable-nodpi/default_wallpaper.*  (注意不能是bmp格式) 替换默认锁屏壁纸: 将图片资源放入vendo