如何让我的模糊动画每次都运行得更快?
How can I make my blur animation works faster everytime?
我尝试模糊所有页面并在单击按钮时显示 "popup form",这确实有效,但第一次单击时动画非常慢,因此我尝试找到任何解决方案解决这个问题
我运行它在本地wamp服务器上,我试过很多浏览器,每次第一次点击似乎都很慢,我什至尝试在线上传网站,结果是一样的.
var vid = document.getElementById("bgvid");
vid.volume = 0.01;
var x = document.getElementById("formregister");
var container = document.getElementById('container');
var top_vid =
document.getElementById('top_vid')
function hideShow()
{
if(x.style.display === "none")
{
x.style.display = "block";
vid.classList.remove('noblur');
top_vid.classList.remove('noblur');
vid.className += " blur";
top_vid.className += " blur";
}
else
{
x.style.display = "none";
vid.className += " noblur";
top_vid.className += " noblur";
vid.classList.remove('blur');
top_vid.classList.remove('blur');
}
}
@import url('https://fonts.googleapis.com/css?family=Montserrat&display=swap');
body{
font-family: 'Montserrat', sans-serif;
background-color: black;
}
.bg,
.bg-filter{
position: fixed;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
}
.bg-filter{
z-index:-99;
opacity:0.2;
background: -webkit-linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
background: -moz-linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
background: -o-linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
background: linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
}
.top_vid{
display: flex;
flex-direction: row;
justify-content: space-between;
}
.top_vid .title{
font-family: 'Montserrat', sans-serif;
margin-left: 3%;
font-size:3.2em;
color:#fff;
}
.start {
overflow: hidden;
font-family: 'Montserrat', sans-serif;
border-radius: 4px;
background-color: transparent;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 28px;
cursor: pointer;
margin-right: 3%;
}
.start:focus{
outline:none;
}
.start span {
cursor: pointer;
position: relative;
transition: 0.5s;
}
.start span:after {
color: #31E0F7;
content: '[=11=]bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.start:hover span {
padding-right: 25px;
}
.start:hover span:after {
opacity: 1;
right: 0;
}
.registerform{
align-items: center;
}
form {
display: flex;
flex-direction: column;
align-items: center;
}
.blur {
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-ms-filter: blur(5px);
-o-filter: blur(5px);
filter: blur(5px);
-webkit-transition: all 0.25s ease-in;
transition: all 0.25s ease-in;
}
.noblur {
-webkit-filter: blur(0px);
-moz-filter: blur(0px);
-ms-filter: blur(0px);
-o-filter: blur(0px);
filter: blur(0px);
-webkit-transition: all 0.25s ease-out;
transition: all 0.25s ease-out;
}
<div id="container">
<video autoplay loop poster class="bg" id="bgvid">
<source src="videos/theforcebg5.mp4" type="video/mp4"></source>
</video>
<div class="bg-filter" id="bg-filter"></div>
<div class="top_vid" id="top_vid">
<h1 class="title">Moodyness</h1>
<button class="start" onclick="hideShow()"><span>Let's move !</span></button>
</div>
</div>
<div class="registerform" id="formregister" style="display: none;">
<form action="#" method="post">
<input type="email" placeholder="EMAIL" required></input>
<input type="password" placeholder="PASSWORD" required></input>
<input type="password" placeholder="REPEAT PASSWORD" required></input>
<div class="check">
<label for="checkbox">Acceptez vous les conditions d'utilisation ?</label>
<input type="checkbox" id="checkbox" required></input>
</div>
<input type="submit" value="Okay !"></input>
</form>
</div>
完整代码在这里https://codepen.io/anon/pen/pmWwxm
我希望即使在我们第一次启动网站时动画也能很快,谢谢!
这与 JavaScript 或 HTML 完全没有关系。它是一个 CSS 属性 处理模糊动画的时间(或 transition)。
你可以在这四行中处理转换的时间:
.blur {
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-ms-filter: blur(5px);
-o-filter: blur(5px);
filter: blur(5px);
-webkit-transition: all 0.1s ease-in; //HERE
transition: all 0.1s ease-in; //HERE
}
.noblur {
-webkit-filter: blur(0px);
-moz-filter: blur(0px);
-ms-filter: blur(0px);
-o-filter: blur(0px);
filter: blur(0px);
-webkit-transition: all 0.1s ease-out; //HERE
transition: all 0.1s ease-out; //HERE
}
你有以下价值观:
transition: all 0.5s ease-out;
因此将其更改为较小的值,如 0.1s
将使转换更快。这就是为什么你的过渡总是相同的速度,因为 transition
CSS 属性 处理当前元素样式到下一个样式之间的时间。
示例: 将 blur(5px)
作为当前值,当您将元素样式更改为 blur(0px)
并且 transition
属性 存在于元素上,CSS 将计算在指定时间内需要将当前值减少多少 5s
所以在这段时间结束时,最终值将是 blur(0px)
.这模拟了模糊动画消失。
看看这里,看看它是否有效:
var vid = document.getElementById("bgvid");
vid.volume = 0.01;
var x = document.getElementById("formregister");
var container = document.getElementById('container');
var top_vid =
document.getElementById('top_vid')
function hideShow()
{
if(x.style.display === "none")
{
x.style.display = "block";
vid.classList.remove('noblur');
top_vid.classList.remove('noblur');
vid.className += " blur";
top_vid.className += " blur";
}
else
{
x.style.display = "none";
vid.className += " noblur";
top_vid.className += " noblur";
vid.classList.remove('blur');
top_vid.classList.remove('blur');
}
}
@import url('https://fonts.googleapis.com/css?family=Montserrat&display=swap');
body{
font-family: 'Montserrat', sans-serif;
background-color: black;
}
.bg,
.bg-filter{
position: fixed;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
}
.bg-filter{
z-index:-99;
opacity:0.2;
background: -webkit-linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
background: -moz-linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
background: -o-linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
background: linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
}
.top_vid{
display: flex;
flex-direction: row;
justify-content: space-between;
}
.top_vid .title{
font-family: 'Montserrat', sans-serif;
margin-left: 3%;
font-size:3.2em;
color:#fff;
}
.start {
overflow: hidden;
font-family: 'Montserrat', sans-serif;
border-radius: 4px;
background-color: transparent;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 28px;
cursor: pointer;
margin-right: 3%;
}
.start:focus{
outline:none;
}
.start span {
cursor: pointer;
position: relative;
transition: 0.1s;
}
.start span:after {
color: #31E0F7;
content: '[=13=]bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.1s;
}
.start:hover span {
padding-right: 25px;
}
.start:hover span:after {
opacity: 1;
right: 0;
}
.registerform{
align-items: center;
}
form {
display: flex;
flex-direction: column;
align-items: center;
}
.blur {
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-ms-filter: blur(5px);
-o-filter: blur(5px);
filter: blur(5px);
-webkit-transition: all 0.1s ease-in;
transition: all 0.1s ease-in;
}
.noblur {
-webkit-filter: blur(0px);
-moz-filter: blur(0px);
-ms-filter: blur(0px);
-o-filter: blur(0px);
filter: blur(0px);
-webkit-transition: all 0.1s ease-out;
transition: all 0.1s ease-out;
}
<div id="container">
<video autoplay loop poster class="bg" id="bgvid">
<source src="videos/theforcebg5.mp4" type="video/mp4"></source>
</video>
<div class="bg-filter" id="bg-filter"></div>
<div class="top_vid" id="top_vid">
<h1 class="title">Moodyness</h1>
<button class="start" onclick="hideShow()"><span>Let's move !</span></button>
</div>
</div>
<div class="registerform" id="formregister" style="display: none;">
<form action="#" method="post">
<input type="email" placeholder="EMAIL" required></input>
<input type="password" placeholder="PASSWORD" required></input>
<input type="password" placeholder="REPEAT PASSWORD" required></input>
<div class="check">
<label for="checkbox">Acceptez vous les conditions d'utilisation ?</label>
<input type="checkbox" id="checkbox" required></input>
</div>
<input type="submit" value="Okay !"></input>
</form>
</div>
我尝试模糊所有页面并在单击按钮时显示 "popup form",这确实有效,但第一次单击时动画非常慢,因此我尝试找到任何解决方案解决这个问题
我运行它在本地wamp服务器上,我试过很多浏览器,每次第一次点击似乎都很慢,我什至尝试在线上传网站,结果是一样的.
var vid = document.getElementById("bgvid");
vid.volume = 0.01;
var x = document.getElementById("formregister");
var container = document.getElementById('container');
var top_vid =
document.getElementById('top_vid')
function hideShow()
{
if(x.style.display === "none")
{
x.style.display = "block";
vid.classList.remove('noblur');
top_vid.classList.remove('noblur');
vid.className += " blur";
top_vid.className += " blur";
}
else
{
x.style.display = "none";
vid.className += " noblur";
top_vid.className += " noblur";
vid.classList.remove('blur');
top_vid.classList.remove('blur');
}
}
@import url('https://fonts.googleapis.com/css?family=Montserrat&display=swap');
body{
font-family: 'Montserrat', sans-serif;
background-color: black;
}
.bg,
.bg-filter{
position: fixed;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
}
.bg-filter{
z-index:-99;
opacity:0.2;
background: -webkit-linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
background: -moz-linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
background: -o-linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
background: linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
}
.top_vid{
display: flex;
flex-direction: row;
justify-content: space-between;
}
.top_vid .title{
font-family: 'Montserrat', sans-serif;
margin-left: 3%;
font-size:3.2em;
color:#fff;
}
.start {
overflow: hidden;
font-family: 'Montserrat', sans-serif;
border-radius: 4px;
background-color: transparent;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 28px;
cursor: pointer;
margin-right: 3%;
}
.start:focus{
outline:none;
}
.start span {
cursor: pointer;
position: relative;
transition: 0.5s;
}
.start span:after {
color: #31E0F7;
content: '[=11=]bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.5s;
}
.start:hover span {
padding-right: 25px;
}
.start:hover span:after {
opacity: 1;
right: 0;
}
.registerform{
align-items: center;
}
form {
display: flex;
flex-direction: column;
align-items: center;
}
.blur {
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-ms-filter: blur(5px);
-o-filter: blur(5px);
filter: blur(5px);
-webkit-transition: all 0.25s ease-in;
transition: all 0.25s ease-in;
}
.noblur {
-webkit-filter: blur(0px);
-moz-filter: blur(0px);
-ms-filter: blur(0px);
-o-filter: blur(0px);
filter: blur(0px);
-webkit-transition: all 0.25s ease-out;
transition: all 0.25s ease-out;
}
<div id="container">
<video autoplay loop poster class="bg" id="bgvid">
<source src="videos/theforcebg5.mp4" type="video/mp4"></source>
</video>
<div class="bg-filter" id="bg-filter"></div>
<div class="top_vid" id="top_vid">
<h1 class="title">Moodyness</h1>
<button class="start" onclick="hideShow()"><span>Let's move !</span></button>
</div>
</div>
<div class="registerform" id="formregister" style="display: none;">
<form action="#" method="post">
<input type="email" placeholder="EMAIL" required></input>
<input type="password" placeholder="PASSWORD" required></input>
<input type="password" placeholder="REPEAT PASSWORD" required></input>
<div class="check">
<label for="checkbox">Acceptez vous les conditions d'utilisation ?</label>
<input type="checkbox" id="checkbox" required></input>
</div>
<input type="submit" value="Okay !"></input>
</form>
</div>
完整代码在这里https://codepen.io/anon/pen/pmWwxm
我希望即使在我们第一次启动网站时动画也能很快,谢谢!
这与 JavaScript 或 HTML 完全没有关系。它是一个 CSS 属性 处理模糊动画的时间(或 transition)。
你可以在这四行中处理转换的时间:
.blur {
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-ms-filter: blur(5px);
-o-filter: blur(5px);
filter: blur(5px);
-webkit-transition: all 0.1s ease-in; //HERE
transition: all 0.1s ease-in; //HERE
}
.noblur {
-webkit-filter: blur(0px);
-moz-filter: blur(0px);
-ms-filter: blur(0px);
-o-filter: blur(0px);
filter: blur(0px);
-webkit-transition: all 0.1s ease-out; //HERE
transition: all 0.1s ease-out; //HERE
}
你有以下价值观:
transition: all 0.5s ease-out;
因此将其更改为较小的值,如 0.1s
将使转换更快。这就是为什么你的过渡总是相同的速度,因为 transition
CSS 属性 处理当前元素样式到下一个样式之间的时间。
示例: 将 blur(5px)
作为当前值,当您将元素样式更改为 blur(0px)
并且 transition
属性 存在于元素上,CSS 将计算在指定时间内需要将当前值减少多少 5s
所以在这段时间结束时,最终值将是 blur(0px)
.这模拟了模糊动画消失。
看看这里,看看它是否有效:
var vid = document.getElementById("bgvid");
vid.volume = 0.01;
var x = document.getElementById("formregister");
var container = document.getElementById('container');
var top_vid =
document.getElementById('top_vid')
function hideShow()
{
if(x.style.display === "none")
{
x.style.display = "block";
vid.classList.remove('noblur');
top_vid.classList.remove('noblur');
vid.className += " blur";
top_vid.className += " blur";
}
else
{
x.style.display = "none";
vid.className += " noblur";
top_vid.className += " noblur";
vid.classList.remove('blur');
top_vid.classList.remove('blur');
}
}
@import url('https://fonts.googleapis.com/css?family=Montserrat&display=swap');
body{
font-family: 'Montserrat', sans-serif;
background-color: black;
}
.bg,
.bg-filter{
position: fixed;
top: 0;
left: 0;
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: -100;
}
.bg-filter{
z-index:-99;
opacity:0.2;
background: -webkit-linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
background: -moz-linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
background: -o-linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
background: linear-gradient(rgba(49,224,247,1) 0%, rgba(90,77,184,1) 100%);
}
.top_vid{
display: flex;
flex-direction: row;
justify-content: space-between;
}
.top_vid .title{
font-family: 'Montserrat', sans-serif;
margin-left: 3%;
font-size:3.2em;
color:#fff;
}
.start {
overflow: hidden;
font-family: 'Montserrat', sans-serif;
border-radius: 4px;
background-color: transparent;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 28px;
cursor: pointer;
margin-right: 3%;
}
.start:focus{
outline:none;
}
.start span {
cursor: pointer;
position: relative;
transition: 0.1s;
}
.start span:after {
color: #31E0F7;
content: '[=13=]bb';
position: absolute;
opacity: 0;
top: 0;
right: -20px;
transition: 0.1s;
}
.start:hover span {
padding-right: 25px;
}
.start:hover span:after {
opacity: 1;
right: 0;
}
.registerform{
align-items: center;
}
form {
display: flex;
flex-direction: column;
align-items: center;
}
.blur {
-webkit-filter: blur(5px);
-moz-filter: blur(5px);
-ms-filter: blur(5px);
-o-filter: blur(5px);
filter: blur(5px);
-webkit-transition: all 0.1s ease-in;
transition: all 0.1s ease-in;
}
.noblur {
-webkit-filter: blur(0px);
-moz-filter: blur(0px);
-ms-filter: blur(0px);
-o-filter: blur(0px);
filter: blur(0px);
-webkit-transition: all 0.1s ease-out;
transition: all 0.1s ease-out;
}
<div id="container">
<video autoplay loop poster class="bg" id="bgvid">
<source src="videos/theforcebg5.mp4" type="video/mp4"></source>
</video>
<div class="bg-filter" id="bg-filter"></div>
<div class="top_vid" id="top_vid">
<h1 class="title">Moodyness</h1>
<button class="start" onclick="hideShow()"><span>Let's move !</span></button>
</div>
</div>
<div class="registerform" id="formregister" style="display: none;">
<form action="#" method="post">
<input type="email" placeholder="EMAIL" required></input>
<input type="password" placeholder="PASSWORD" required></input>
<input type="password" placeholder="REPEAT PASSWORD" required></input>
<div class="check">
<label for="checkbox">Acceptez vous les conditions d'utilisation ?</label>
<input type="checkbox" id="checkbox" required></input>
</div>
<input type="submit" value="Okay !"></input>
</form>
</div>