RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1368039
Accepted
Majestio
Majestio
Asked:2022-06-03 15:06:49 +0000 UTC2022-06-03 15:06:49 +0000 UTC 2022-06-03 15:06:49 +0000 UTC

使背景变亮的动画 SVG 蒙版

  • 772

我们需要如下动画效果:

加载了某种背景的 HTML 页面,尽管是深蓝色的。
1s 后,SVG 图像从上到下向屏幕中心滑动,这只会使现有背景变亮(充当蒙版)。

应该看起来像这样:

在此处输入图像描述

请帮助实施,或至少提示在哪里挖掘。如果没有 Javascript - 它通常会超级棒!

javascript
  • 3 3 个回答
  • 10 Views

3 个回答

  • Voted
  1. Monkey Mutant
    2022-06-04T18:09:47Z2022-06-04T18:09:47Z

    javascript 以便 svg 始终处于屏幕的 100% - 也许我太聪明了,但是看,任何值都可以更改

    这是一个稍微好一点的:https ://codepen.io/topicstarter/pen/OJxZEMN

    let body = document.querySelector("body");
    let w = body.getBoundingClientRect().width;
    let h = body.getBoundingClientRect().height;
    
    svg.setAttribute("width", w + "px");
    svg.setAttribute("height", h + "px");
    
    window.addEventListener("resize", function() {
      svg.setAttribute("width", w + "px");
      svg.setAttribute("height", h + "px");
    })
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    
    html,
    body,
    .parent {
      height: 100%;
    }
    
    .parent,
    #svg {
      position: absolute;
      width: 100%;
      height: 100%;
      top: 0;
      left: 0;
    }
    
    img {
      display: block;
      width: 100%;
      height: 100%;
      object-fit: cover;
      position: absolute;
      top: 0;
      left: 0;
    }
    
    svg {
      z-index: 100;
      outline: 3px solid red;
    }
    <div class="parent">
      <div class="background">
        <img src="https://catherineasquithgallery.com/uploads/posts/2021-02/1614429316_25-p-temno-sinii-fon-dlya-fotoshopa-29.jpg" alt="">
      </div>
      <div class="svg">
        <svg id="svg">
          <rect width="100%" height="100%" fill="#000" fill-opacity="0.8">
            <animate attributeName="height" repeatCount="1" begin="1s" values="100%; 50%"dur="1s" />
            <animate attributeName="y"  repeatCount="1" begin="1s" values="0%; 50%" dur="1s" fill="freeze"/>
          </rect>
        </svg>
      </div>
    </div>

    • 2
  2. Best Answer
    Alexandr_TT
    2022-06-04T20:49:15Z2022-06-04T20:49:15Z

    对于将从上到下到屏幕中间的 SVG 图像,我选择了徽标Adobe

    1. 页面加载后 1.5 秒的徽标移动: animation:adobe 2s forwards 1.5s;

    使用 SVG 蒙版为背景设置动画和变亮是从问题中已编辑的示例中完成的。在徽标上添加了另一个链接。

    .container {
      display: flex;
      height: 100vh;
    }
    
    .main {
      display: flex;
      flex-direction: column;
      flex-grow: 1;
      height: 100vh;
    }
    
    body {
      margin: 0;
      padding: 0
    }
    
    .header {
      background: #FFDD00;
      height: 50px;
      text-align:center;
      font-size:24px;
      color:#151515;
      padding-top:0.5em;
      z-index:1;
    }
    
    
    .sidebar {
      width: 15%;
      height: 100%;
      background: #5677FC;
      text-align:center;
      font-size:24px;
      color:white;
    }
    
    .content {
      background-color: #3B3A75;
      font-size:24px;
      color:white;
      height: 100%;
      padding:1em;
      position:relative;
     
    }
    
    .adobe {
    width:300px;
    position: absolute;
      margin: 0 auto;
      top:-115%;
      left: 0;
      right: 0;
      animation:adobe 2s forwards 1.5s;
    }
    
    @keyframes adobe {
    100%{top:40%;}
    }
    <div class="container">
      <div class="sidebar">sidebar</div>
      <div class="main">
        <div class="header">header</div>
        <div class="content">content</div>
         <div class="adobe">
           <a href="https://ru.stackoverflow.com/questions/tagged/svg">        
           <svg  viewBox="0 0 105 93" xmlns='http://www.w3.org/2000/svg'>
            <mask id="msk">
                <rect  width="420" height="372" fill="white" />
              <path fill-rule="nonzero" d='M66,0h39v93zM38,0h-38v93zM52,35l25,58h-16l-8-18h-18z' fill='black'/>
            </mask> 
                <rect  width="420" height="372" fill="#6260B7" />        
                 <rect mask="url(#msk)" x="0"  width="420" height="372" fill="#3B3A75" />
    </svg> 
     </a>
         </div>
      </div>
    </div>

    • 2
  3. Alexandr_TT
    2022-06-11T23:58:11Z2022-06-11T23:58:11Z

    为了避免在全屏模式下出现垂直滚动条,需要不指定SVG图像的高度和宽度,还需要将svg块包裹在父容器中 - ,以相对单位<div class="container"> 指定. 在这种情况下,svg 将响应并填充整个父容器。widthheight

    如果片段窗口中的滚动条干扰,则必须为父容器指定width:"25vw" height:25vh。当全屏打开时,应用程序会自适应增加。
    在实际应用中,指定width:"100vw" height:100vh属时。任何最大 svg 大小的容器,它都会缩小到浏览器屏幕的大小,当您缩小浏览器窗口或使用另一个显示较小的小工具时,SVG 图像将调整到此显示的大小。

    .container {
      width:25vw;
      height: 25vh;
      background-color: #3B3A75;
      color:white;
    }
    <div class="container"> content 
         
           <a href="https://ru.stackoverflow.com/questions/tagged/svg">        
           <svg  viewBox="0 0 105 93" xmlns='http://www.w3.org/2000/svg'>
            <mask id="msk">
                <rect  width="100%" height="100%" fill="white" />
              <path id="path" fill-rule="nonzero" transform="scale(0.5) translate(52.5 -120.5)" d='M66,0h39v93zM38,0h-38v93zM52,35l25,58h-16l-8-18h-18z' fill='black'>
               
              </path>
            </mask> 
                <rect  width="100%" height="100%" fill="#6260B7" />      
                 <rect mask="url(#msk)" x="0"  width="100%" height="100%" fill="#3B3A75" /> 
              <animateTransform xlink:href="#path"
               attributeName="transform"
                type="translate"
                begin="0s" dur="2s"
                values="0 0;0 150"
                fill="freeze"
                additive="sum"
                restart="whenNotActive"/>    
    </svg> 
     </a>
     </div>

    • 2

相关问题

  • 第二个 Instagram 按钮的 CSS 属性

  • 由于模糊,内容不可见

  • 弹出队列。消息显示不正确

  • 是否可以在 for 循环中插入提示?

  • 如何将 JSON 请求中的信息输出到数据表 Vuetify vue.js?

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5