使用 jquery 的简单 .animate
Simple .animate with jquery
出于某种原因,每次我尝试将 jquery 实现到我的代码中时,它都不起作用。我知道编写 jquery 的基础知识并查找我正在尝试做的事情,但即使我的代码与在线示例完全相似,显然也永远无法正确完成。
我在这里要做的就是让#time 从屏幕外向下滑动到页面加载时的正常位置。我尝试了 .slideDown 和 .animate(顶部)
<div id="time">
<h1>Good Evening</h1>
</div>
#time {
width: 100%;
height: 50px;
background-color: #000;
}
#time h1 {
color: #D4AF37;
font-size: 38px;
font-family: 'Arimo', sans-serif;
font-weight: 700;
text-align: center;
letter-spacing: 5px;
font-style: italic;
margin-top: 0px;
line-height: 50px;
}
$(function() {
$('#time').animate({
top: '50px'), 200
});
});
您的脚本中存在一些语法错误,您还忘记了 css 中的 position
。
脚本
$(document).ready(function() {
$('#time').animate({
top: '50px'}, 2000
);
});
CSS
#time {
width: 100%;
height: 50px;
background-color: #000;
position:absolute
}
请在此处查看工作解决方案:
https://jsfiddle.net/aq9hszmv/2/
$(function() {
$('#time').animate({
top: '0px'}, 2000
);
});
#time {
width: 100%;
height: 50px;
background-color: #000;
top: -50px;
position: absolute;
}
出于某种原因,每次我尝试将 jquery 实现到我的代码中时,它都不起作用。我知道编写 jquery 的基础知识并查找我正在尝试做的事情,但即使我的代码与在线示例完全相似,显然也永远无法正确完成。
我在这里要做的就是让#time 从屏幕外向下滑动到页面加载时的正常位置。我尝试了 .slideDown 和 .animate(顶部)
<div id="time">
<h1>Good Evening</h1>
</div>
#time {
width: 100%;
height: 50px;
background-color: #000;
}
#time h1 {
color: #D4AF37;
font-size: 38px;
font-family: 'Arimo', sans-serif;
font-weight: 700;
text-align: center;
letter-spacing: 5px;
font-style: italic;
margin-top: 0px;
line-height: 50px;
}
$(function() {
$('#time').animate({
top: '50px'), 200
});
});
您的脚本中存在一些语法错误,您还忘记了 css 中的 position
。
脚本
$(document).ready(function() {
$('#time').animate({
top: '50px'}, 2000
);
});
CSS
#time {
width: 100%;
height: 50px;
background-color: #000;
position:absolute
}
请在此处查看工作解决方案:
https://jsfiddle.net/aq9hszmv/2/
$(function() {
$('#time').animate({
top: '0px'}, 2000
);
});
#time {
width: 100%;
height: 50px;
background-color: #000;
top: -50px;
position: absolute;
}