前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >前端特效学习1

前端特效学习1

作者头像
用户7162790
发布2022-03-23 14:32:08
5870
发布2022-03-23 14:32:08
举报
文章被收录于专栏:森屿暖树

前言

今天找素材的时候,发现明天(1月5日)是宫崎骏爷爷80岁生日,祝宫崎骏爷爷福如东海,寿比南山。

效果图

day1
day1

HTML代码

代码语言:javascript
复制
  <!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title>1.4</title>
    <link rel="stylesheet" href="css/style.css" />
</head>
<body>
    <div class="cont">
        <h1>宫崎骏</h1>
        <div class="demo one">
            <img class="img" src="img/img1.png">
            <div class="text">
                <p class="title">幽灵公主</p>
            </div>
        </div>
        <div class="demo two">
            <img class="img" src="img/img2.png">
            <div class="text">
                <p class="title">千与千寻</p>
            </div>
        </div>
        <div class="demo three">
            <img class="img" src="img/img3.png">
            <div class="text">
                <p class="title">移动的城堡哈尔</p>
            </div>
        </div>
    </div>
    <script>
    var cards = document.querySelector(".cont");
    var images = document.querySelectorAll(".img");
    var range = 40;
    var calcValue = function calcValue(a, b) {
    return(a / b * range - range / 2).toFixed(1);
    };
    var timeout = void 0;
    document.addEventListener('mousemove', function(_ref) {
    var x = _ref.x,
    y = _ref.y;
    if(timeout) {
    window.cancelAnimationFrame(timeout);
    }
    timeout = window.requestAnimationFrame(function() {
    var yValue = calcValue(y, window.innerHeight);
    var xValue = calcValue(x, window.innerWidth);
    console.log(xValue, yValue);
    cards.style.transform = "rotateX(" + yValue + "deg) rotateY(" + xValue + "deg)";
    [].forEach.call(images, function(image) {
    image.style.transform = "translateX(" + -xValue + "px) translateY(" + yValue + "px)";
    });
    [].forEach.call(backgrounds, function(background) {
    background.style.backgroundPosition = xValue * .45 + "px " + -yValue * .45 + "px";
    });
    });
    }, false);
    </script>
</body>
</html>

css代码

代码语言:javascript
复制
html, body {
  height: 100%;
}

body {
  align-items: center;
  background: linear-gradient(to bottom, #ecb390, #949cdf);
  display: flex;
  justify-content: center;
  overflow: hidden;
  -webkit-perspective: 1800px;
          perspective: 1800px;
  margin: 0 20px;
}

h1 {
  transform: translateZ(50px);
  text-align: center;
}

.cont {
  background: #fff;
  border-radius: 15px;
  box-shadow: 0px 10px 20px 20px rgba(255, 255, 255, 0.37);
  display: inline-block;
  padding: 30px 35px;
  -webkit-perspective: 1800px;
          perspective: 1800px;
  text-align: left;
  -webkit-transform-origin: 50% 50%;
          transform-origin: 50% 50%;
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
  -webkit-transform: rotateX(11deg) rotateY(16.5deg);
          transform: rotateX(11deg) rotateY(16.5deg);
  min-width: 595px;
}

.demo {
  border-radius: 15px;
  box-shadow: 0px 0px 1px -0px rgba(0, 0, 0, 0.6);
  display: inline-block;
  height: 250px;
  overflow: hidden;
  -webkit-perspective: 1200px;
          perspective: 1200px;
  position: relative;
  -webkit-transform-style: preserve-3d;
          transform-style: preserve-3d;
  -webkit-transform: translatez(35px);
          transform: translatez(35px);
  transition: -webkit-transform 200ms ease-out;
  transition: transform 200ms ease-out;
  transition: transform 200ms ease-out, -webkit-transform 200ms ease-out;
  width: 175px;
  text-align: center;
}
.demo:not(:last-child) {
  margin-right: 30px;
}

.img {
  position: relative;
  height: 100%;
}

.one .img {
  top: 14px;
  right: -10px;
  height: 110%;
}

.two .img {
  top: 25px;
}

.three .img {
  top: 5px;
  left: -4px;
  height: 110%;
}

.text {
  align-items: center;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.55) 100%);
  bottom: 0;
  display: flex;
  flex-direction: column;
  height: 70px;
  justify-content: center;
  position: absolute;
  width: 100%;
  z-index: 2;
}

.title {
  color: #fff;
  font-size: 18px;
  font-weight: 700;
  padding: 0 10px;
  margin-bottom: 3px;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • 效果图
  • HTML代码
  • css代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档