【发布时间】:2019-08-20 02:29:23
【问题描述】:
我正在尝试完成一个简单的过渡。我希望“欢迎”文本同时向下移动并按比例缩放。
似乎当我运行此代码时,“欢迎”文本略微向下移动,停止,文本大小增加到 js 中指定的数量,然后它继续移动到我在 js 中指定的位置。
我做错了什么以及如何让他们同时过渡?
https://codepen.io/anon/pen/JzgwNx
谢谢。
$(document).ready(function(){
$("#welcome").animate({top: "300px"}, 1500 );
$("#welcome").css({fontSize: "70px", transition: "1.5s"});
});
.container {
width: 1000px;
margin: 0 auto;
border: 1px solid black;
}
p {
font-size: 5em;
color: white;
font-family: "Helvetica";
text-align: center;
margin-top: 153px;
}
nav {
background: transparent;
height: 3vw;
/*width: 100%;*/
text-align: right;
}
ul {
margin-top: 17;
}
nav li {
display: inline;
/*float: right;*/
margin: 0 5px;
padding: 10px;
padding-top: 15px;
}
nav a {
text-decoration: none;
font-size: 20px;
color: white;
font-family: "Helvetica";
transition: 0.25s;
}
nav a:hover {
border-bottom: 3px solid gray;
padding-bottom: 5px;
font-size: 22px;
font-weight: 500;
transition: 0.25s;
}
header {
background: url(main.jpg);
height: 100vh;
}
#welcome {
color: black;
font-family: "Helvetica";
font-size: 30px;
text-align: center;
position: relative;
}
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<header>
<nav>
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
<h1 id="welcome">Welcome</h1>
</header>
【问题讨论】:
-
CSS3 以 jQuery 永远无法处理的帧速率支持所有这些。你为什么要为此使用 jQuery?
-
发生这种情况是因为当你在 JS 中设置
transitioninline 时,它默认为all。这意味着除了动画之外,top的变化也得到了过渡。 Here我已将JS更改为设置transitionDuration,同时在样式中指定仅转换font-size。
标签: jquery jquery-animate css-transitions timing