javascript - 如何扩展背景图像以填充整个页面?
问题描述
我在左上角创建了一个固定位置按钮的动画,它创建了一个背景,点击时会在整个页面上展开。所以我写了一个这样的 CSS:它只扩展到父元素,但我该怎么做一个延伸到整个页面的动画?
div {
height: 200px;
width: 200px;
background: radial-gradient(circle at center, blue 50%, transparent 50%);
background-size: 10% 10%;
background-position: center;
background-repeat: no-repeat;
transition: all .5s;
}
div:hover {
background-size: 200% 200%;
}
<div></div>
解决方案
您可以考虑如下所示的伪元素:
.box {
height: 200px;
width: 200px;
position: relative;
}
.box:before {
content: "";
position: absolute;
top: -100vh;
bottom: -100vh;
left: -100vw;
right: -100vw;
background: radial-gradient(circle, blue 50%, transparent 50%) center no-repeat;
background-size: 20px 20px;
transition: all .5s;
pointer-events:none;
}
.box:hover::before {
background-size: 200% 200%;
}
html {
overflow:hidden;
}
<div class="box"></div>
推荐阅读
- r - 如何创建一组虚拟变量来标识另一个变量中的特定值?
- docker - Rancher:在 CERTIFICATE_VERIFY_FAILED 上向 Rancher 添加另一个主机失败
- powershell - 如何使用 Powershell 查找具有给定名称的所有空目录?
- intellij-idea - IntelliJ IDEA - 出现在项目文件中但不在项目中的目录
- python-3.x - 想在 Airflow 中使用 TriggerDagRunOperator 通过仅使用 Main-dag 和 bashoperator(子 dag 运算符)来触发许多子 dag
- linux - 如何过滤“diff”命令以排除某些条目?
- python-3.x - 当我从另一个 .py 文件调用函数时,我的代码挂起
- angular - 如何在 Angular 8 中正确使用 PrimeNg Toast
- regex - 搜索和替换中的正则表达式:避免固定长度的环视
- sharepoint-2010 - 复选框和下拉列表 SharePoint 2013 的自定义 Web 属性