javascript - 在图像上带来盒子阴影效果
问题描述
这是将图像插入动画帧的代码。该代码工作正常,除了一个我找不到解决方案的烦人问题。
我想要图像上的框阴影效果,但出乎意料的是它现在在图像下方。这是中的 box-shadow CSS.box .content
box-shadow: 0 0 0.262vh deeppink, 0 0 0.6553vh rgba(0, 0, 0, 1), inset 0 0 0.6553vh rgba(0, 0, 0, 1);
这是代码:(我在很多方面都尝试过 z-index,但我认为我需要帮助才能正确使用它!)
const content = document.querySelector('.content');
let image = document.createElement('img');
content.appendChild(image);
image.id = 'shot';
image.src = 'https://static01.nyt.com/images/2020/01/30/t-magazine/oakImage-1580415371326/oakImage-1580415371326-superJumbo.jpg';
let shot = document.getElementById("shot");
shot.onload = function() {
imageWidth = this.naturalWidth;
imageHeight= this.naturalHeight;
//console.log(imageWidth, imageHeight);
let viewPortClipWidth = imageWidth * (100 / document.body.clientWidth);
let viewPortClipHeight = imageHeight * (100 / document.body.clientHeight);
//console.log(viewPortClipWidth, viewPortClipHeight);
document.querySelector('.box .content').style.width = `${viewPortClipWidth}vw`;
document.querySelector('.box .content').style.height = `${viewPortClipHeight}vh`;
}
img {
position: absolute;
top: 0;
left: 0;
max-width: 100%;
max-height: 100%;
width: 100%;
height: 100%;
-o-object-fit: cover;
object-fit: cover;
}
body {
height: 100vh;
margin:0;
display: flex;
align-items: center;
justify-content: center;
background-color: #11151a;
}
.box {
border-radius: 0.5vh;
position: relative;
overflow: hidden;
}
.box::after {
content: '';
position: absolute;
z-index: -1;
top: 0;
right: 0;
bottom: 0;
left: 0;
background:
repeating-linear-gradient(-45deg, white 0 0.48828125vw, #f00c36 0 0.9765625vw) 0 0/1.380859375vw 1.380859375vw;
width: calc(100% + 1.380859375vw);
height: calc(100% + 1.380859375vw);
transform: translate(-1.380859375vw, -1.380859375vw);
will-change: transform;
animation: animate 4s linear infinite;
}
.box .content {
position: relative;
max-width: 93vw;
max-height: 89vh;
box-shadow: 0 0 0.262vh deeppink, 0 0 0.6553vh rgba(0, 0, 0, 1), inset 0 0 0.6553vh rgba(0, 0, 0, 1);
margin:0.3vw;
}
@keyframes animate {
to {
transform: translate(0, 0);
will-change: transform;
}
}
<div id='box' class="box">
<div class="content"></div>
</div>
解决方案
推荐阅读
- django - 在 AWS 上运行 Django REST-API - apache 服务器什么都不做
- r - 从包含R中每行列表中的列表的数据帧的每一行中提取一个参数
- .net - Azure Service Bus: Microsoft.Azure.WebJobs.Script.HostDisposedException: The host is disposed and cannot be used
- mqtt - MQTT 订阅是否对非干净连接具有幂等性
- javascript - JavaScript - 表单提交上的 beforeunload 覆盖
- python - 我无法在 Flask-admin 中更改 is_accessible
- c - C 中带有回调函数的异步 I/O —— I/O 线程究竟何时以及如何返回?
- apiconnect - Assemble 中的编辑值
- php - 如何使用 PHP 检查检查器中的单选按钮值是否未更改?
- elasticsearch - 仅在具有给定字段值的文档中进行 Elasticsearch 更像这种(MLT)查询?