使用javascript、Ajax制作前端拟态风格天气预报功能

博主通过javascript和Ajax技术创建了一个拟态风格的天气预报功能。项目包含weather.html、weather.css、weathericon.css和iconfont.css四个文件,其中weather.js负责实现动态效果,weathericon.css用于绘制天气图标,iconfont.css则是字体样式。展示了一款具有视觉吸引力的天气信息展示板块。
摘要由CSDN通过智能技术生成

weather.html

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/weather.css">
    <link rel="stylesheet" href="css/weathericon.css">
    <link rel="stylesheet" href="css/iconfont.css">
    <title>Document</title>
</head>
<body>
    <!--    今日天气    -->
    <div class="information"></div>
    <!--    天气预报    -->
    <div class="forecast"> </div>
    <!-- 搜狐家查询ip地址的接口 -->
    <script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
    <script src="js/weather.js"></script>
</body>
</html>

weather.css

整个板块的样式

* {
   
    padding: 0;
    margin: 0;
}
/* 今日天气样式 */
.information {
   
    position: absolute;

}
.now {
   
    position: relative;
    left: 50px;
    top: 40px;
    width: 550px;
    height: 450px;
    border-radius: 50px;
    background: #e6eef4;
    box-shadow: 20px 20px 60px #c4cacf,
        -20px -20px 60px #ffffff;
}
/* 城市名字样式 */
.city {
   
    position: relative;
    left: 300px;
    top: 40px;
    font-size: 35px;
    display: block;
    width: 200px;
    height: 50px;
    text-align: center;
    border-radius: 30px;
    box-shadow: 18px 18px 30px rgba(0, 0, 0, 0.1),
        -18px -18px 30px rgba(255, 255, 255, 1);
}
/* 今日天气样式 */
.text {
   
    position: relative;
    font-size: 30px;
    left: 310px;
    top: 70px;
    display: inline-block;
    width: 180px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    box-shadow: 18px 18px 30px rgba(0, 0, 0, 0.1),
        -18px -18px 30px rgba(255, 255, 255, 1);
    border-radius: 30px;
}
/* 天气图标样式 */
.weatherDiv {
   
    position: relative;
    left: 70px;
    top: -60px;
    width: 150px;
    height: 150px;
    border-radius: 70px;
    box-shadow: 18px 18px 30px rgba(0, 0, 0, 0.1),
        -18px -18px 30px rgba(255, 255, 255, 1);
}
.weatherDiv:hover{
   
    box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.2),
        0px 0px 0px rgba(255, 255, 255, 0.8),
        inset 18px 18px 30px rgba(0, 0, 0, 0.1),
        inset -18px -18px 30px rgba(255, 255, 255, 1);
    transition: box-shadow .2s ease-out;
}
.weather{
   
    padding: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
}
/* 天气信息样式 */
.container {
   
    width: 560px;
    position: relative;
    top: -50px;
}
/* 信息图标显示样式 */
.container .box {
   
    display: flex;
    float: left;
    justify-content: space-around;
    flex-direction: column;
    align-items: center;
    align-content: center;
    width: 100px;
    height: 100px;
    margin: 20px;
}
.container .box .img {
   
    /* width: 100px; */
    width: 78px;
    height: 100px;
    box-shadow: 18px 18px 30px rgba(0, 0, 0, 0.1),
        -18px -18px 30px rgba(255, 255, 255, 1);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #efeeee;
    transition: box-shadow .2s ease-out;
    position: relative;
}
.container .box .img:hover {
   
    box-shadow: 0px 0px 0px rgba(0, 0, 0, 0.2),
        0px 0px 0px rgba(255, 255, 255, 0.8),
        inset 18px 18px 30px rgba(0, 0, 0, 0.1),
        inset -18px -18px 30px rgba(255, 255, 255, 1);
    transition: box-shadow .2s ease-out;
}
/* 天气预测样式 */
.forecast {
   
    position: relative;
    top: 550px;
    left: 70px;
    width: 500px;
    background-color: rgba(0, 0, 0, .3);
    margin: 0 0.2rem;
    border-radius: 20px;
}
.forecast-situation img{
   
    width: 30px;
    height: 30px;
}
.forecast-item {
   
    height: 50px;
    display: flex;
    justify-content: space-between;
    padding: 20px;
}
.forecast-temp {
   
    line-height: 40px;
}

weathericon.css

这个部分的代码主要是用来制作天气图标

/* 所有的动画准备 */
/* 清除所有列表项的默认样式 */

li {
   
    list-style: none;
}

p {
   
    width: 100px;
    height: 150px;
    background: cadetblue;
    float: left;
    margin-right: 20px;
}

/* 进出动画 */
@keyframes inex {
   
    50% {
   
        opacity: 0.4;
    }

    60% {
   
        opacity: 1;
    }
}

/* 移动动画 */
@keyframes move {
   
    50% {
   
        transform: translateX(-10px);
    }
}

/* 降落动画 */
@keyframes fall {
   
    10% {
   
        opacity: 0.8;
    }

    50% {
   
        opacity: 1;
        transform: translate(-10px, 30px);
    }

    100% {
   
        transform: translate(-25px, 70px);
    }
}

/* 闪动动画 */
@keyframes flash {
   
    48% {
   
        background-color: #607d8b;
    }

    50% {
   
        background-color: #fff;
    }

    55% {
   
        background-color: #607d8b;
    }

    57% {
   
        background-color: #fff;
    }
}

/* 流星动画 */
@keyframes meteor {
   
    10% {
   
        opacity: 1;
    }

    80% {
   
        left: 10%;
        top: 75%;
        opacity: 0;
    }
}

/* 雾天 */
.fog {
   
    position: relative;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    background: linear-gradient(to top right, #889ba8 0%, #c0cfd8 40%);
    box-shadow: 1px 1px 30px #515658;
}

.fog .cloud1 {
   
    position: absolute;
    right: 50px;
    top: 10px;
    box-shadow: 1px 1px 30px #0097a7;
    animation: move 3s infinite linear;
}

.fog .cloud1 li:nth-child(1) {
   
    width: 20px;
    height: 20px;
    position: absolute;
    top: 0px;
    left: 0;
    border-radius: 50%;
    background-color: #9bb6b6;
}

.fog .cloud1 li:nth-child(2) {
   
    width: 30px;
    height: 30px;
    position: absolute;
    top: -10px;
    left: 10px;
    border-radius: 50%;
    background-color: #9bb6b6;
}

.fog .cloud1 li:nth-child(3) {
   
    width: 20px;
    height: 20px;
    position: absolute;
    top: 0px;
    left: 30px;
    border-radius: 50%;
    background-color: #9bb6b6;
}

.fog .cloud1 li:nth-child(4) {
   
    width: 40px;
    height: 10px;
    position: absolute;
    top: 10px;
    left: 5px;
    border-radius: 20%;
    background-color: #9bb6b6;
}

.fog .cloud2 {
   
    position: absolute;
    right: 80px;
    top: 15px;
    animation: move 3s infinite linear;
}

.fog .cloud2 li:nth-child(1) {
   
    width: 30px;
    height: 30px;
    position: absolute;
    top: 0px;
    left: 0;
    border-radius: 50%;
    background-color: #9bb6b6;
}

.fog .cloud2 li:nth-child(2) {
   
    width: 40px;
    height: 40px;
    position: absolute;
    top: -10px;
    left: 15px;
    border-radius: 50%;
    background-color: #9bb6b6;
}

.fog .cloud2 li:nth-child(3) {
   
    width: 30px;
    height: 30px;
    position: absolute;
    top: 0px;
    left: 40px;
    border-radius: 50%;
    background-color: #9bb6b6;
}

.fog .cloud2 li:nth-child(4) {
   
    width: 50px;
    height: 15px;
    position: absolute;
    top: 15px;
    left: 10px;
    border-radius: 20%;
    background-color: #9bb6b6;
}

.fog .fogs {
   
    position: absolute;
    right: 20px;
    top: 46px;
}

.fog .fogs li {
   
    width: 60px;
    height: 4px;
    animation: move 3s infinite linear;
    background: linear-gradient(135deg, transparent, transparent 45%, #9bb6b6, transparent 55%, transparent 100%), linear-gradient(45deg, transparent, transparent 45%, #9bb6b6, transparent 55%, transparent 100%);
    background-size: 8px 8px;
    background-repeat: repeat-x, repeat-x;
}

/* 小雨 */
.light-rain {
   
    position: relative;
    width: 130px;
    height: 130px;
    border-radius: 50%;
    background: linear-gradient(to top right, #9ccc65 0%, #26c6da 50%);
    box-shadow: 1px 1px 30px #26c6da;
}

.light-rain .cloud {
   
    position: absolute;
    right: 60px;
    top: 15px;
}

.light-rain .cloud li:nth-child(1) {
   
    width: 25px;
    height: 25px;
    position: absolute;
    top: 0px;
    left: 0;
    border-radius: 50%;
    background-color: #81d4fa;
}

.light-rain .cloud li:nth-child(2) {
   
    width: 35px;
    height: 35px;
    position: absolute;
    top: -10px;
    left: 15px;
    border-radius: 50%;
    background-color: #81d4fa;
}

.light-rain .cloud li:nth-child(3) {
   
    width: 25px;
    height: 25px;
    position: absolute;
    top:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值