英语不是我的第一语言,所以很难解释细节,但我会尽我所能。我真的很抱歉。
我正在制作缩略图扩展全屏过渡。 喜欢google photos ,缩略图应该扩展到全屏并且变换动画也应该适用。
我的方法是对点击的元素进行克隆,
然后设置初始样式(顶部和左侧、宽度和高度等)与原始元素
和添加类,将位置设置为零,并使其完全展开。 width:100vw and height:100vh, top:0 left:0, position:fixed(class .fullscreen) 是它。
我在 http://jsfiddle.net/a7nzy6w6/299/ 上借用了一些想法这里。
但在设置样式时,
clone.style.top = rect.top;
clone.style.left = rect.left;
clone.style.height = img.offsetHeight
clone.style.width = img.offsetWidth
这种方法将替换所有子类的顶部、左侧和高度宽度。甚至它也会也忽略“全屏”类。
所以它不会变形或扩展并保持原始样式。如果我不设置样式,变换动画将不适用。
我如何应用全屏扩展变换动画?有没有更好的解决方案? 或者我如何将元素的初始样式设置为子样式而不替换 javascript 中添加的类?
再次,我真的很抱歉我的英语。我尽力了
顺便说一下,我不知道为什么 element.style 在片段中不起作用
function handler(element)
{
var type = element.getAttribute("data-type")
switch(type)
{
case "image":
transition_fullscreen(element);
break;
default:
break;
}
}
function transition_fullscreen(element)
{
var img = element.getElementsByClassName('el_view')[0];
var rect = img.getBoundingClientRect();
var clone = img.cloneNode(true);
clone.style.top = rect.top;
clone.style.left = rect.left;
clone.style.height = img.offsetHeight
clone.style.width = img.offsetWidth
clone.classList.add('fullscreen');
var ap = document.getElementById('form').appendChild(clone);
}
#form
{
width: 100%;
text-align:center;
}
#form .element
{
display:inline-block;
float:left;
width: 10%;
height: 20%;
margin: 1.9em;
cursor: default;
transition: background .1s ease-in-out;
animation:animatezoom 0.5s;
}
#form .highlight
{
padding:14px;
transition: transform .1s ease-out;
padding-top:auto;
/*border: 1px solid #ddd;
border-radius: 4px;*/
}
#form .highlight:hover { transform: translateY(-0.5rem) scale(1.0125);
box-shadow: 0 0.5em 1.9rem -1rem rgba(0,0,0,0.5); }
#form .highlight:active { transform:scale(0.8); }
#form .el_img { max-height: 124px; vertical-align: middle; }
#form .el_img img { max-width: 88px; max-height: 124px; margin-top: 5%; border-radius:5px; box-shadow:0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12); border-radius:5px;
opacity: 1;
transition: all 3s;
}
#form .el_img .fullscreen
{
z-index:9999;
max-width:100vw;
max-height:100vh;
width:100vw;
height:100vh;
position:fixed;
top:1%;
left:1%;
transition: all 3s;
}
<div id="form">
<div id="element#somefile.exe" class="element" data-type="image" data-link="somefile.exe" onclick=handler(this); title="somefile.exe">
<div id="highlight#somefile.exe" class="highlight">
<div id="content#somefile.exe" class="content">
<div id="el_img#somefile.exe" class="el_img">
<img id="view#somefile.exe" class="el_view" src="https://lh3.googleusercontent.com/oKsgcsHtHu_nIkpNd-mNCAyzUD8xo68laRPOfvFuO0hqv6nDXVNNjEMmoiv9tIDgTj8=w170">
</div>
<div id="el_name#somefile.exe" class="el_name">
somefile.exe
</div>
</div>
</div>
</div>
<div id="element#somefile.exe" class="element" data-type="image" data-link="somefile.exe" onclick=handler(this); title="somefile.exe">
<div id="highlight#somefile.exe" class="highlight">
<div id="content#somefile.exe" class="content">
<div id="el_img#somefile.exe" class="el_img">
<img id="view#somefile.exe" class="el_view" src="https://lh3.googleusercontent.com/hYQO8ekNvsPWMSzMe6IZdCAT6p8qq-SlzA0jiZstV7qBcWg5kn-39qHY0ZaBPqd3usc=w170">
</div>
<div id="el_name#somefile.exe" class="el_name">
blahblah.exe
</div>
</div>
</div>
</div>
<div id="element#somefile.exe" class="element" data-type="image" data-link="somefile.exe" onclick=handler(this); title="somefile.exe">
<div id="highlight#somefile.exe" class="highlight">
<div id="content#somefile.exe" class="content">
<div id="el_img#somefile.exe" class="el_img">
<img id="view#somefile.exe" class="el_view" src="https://lh3.googleusercontent.com/UMB2HRRRAAzXAEaCM9Gg-baCaDx_1RTXHscW5k2Ge3P4KP4mwTt2m6oyEHBWex3c4SxU=w300">
</div>
<div id="el_name#somefile.exe" class="el_name">
mehhhhh.cool
</div>
</div>
</div>
</div>
</div>
最佳答案
我创立了它:
在您的 CSS 中,您可以像这样搜索图像:
#form .el_img .fullscreen
这将在 .el_img
中搜索 #form
中的元素,并且它们具有 fullsceen
类。
但不是 #form
中同时具有 el_img
和 fullscreen
类的元素。
所以你需要从你的选择中删除 .el_img
之前的空格,这样它看起来像这样:
#form .el_img.fullscreen {
/* Rest of your code */
它会起作用。
演示:https://www.w3schools.com/code/tryit.asp?filename=FOBUOKP41CYW
关于javascript - 全屏展开变换并将元素样式设置为子元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48720673/