[英]I'm having trouble getting .animate() to work
Link: https://jsfiddle.net/nbonne/9hcoy9j8/ 链接: https : //jsfiddle.net/nbonne/9hcoy9j8/
I aim is to have the medium blue box and everything in it move up when the search button is pressed. 我的目标是在按下搜索按钮时使用中蓝色框并且其中的所有内容都会向上移动。
I know my selector is for "form" and it's trying to change the background, I'm having trouble getting anything to animate. 我知道我的选择器是用于“形式”而它正在尝试改变背景,我无法获得任何动画效果。
I think this is the correct way to accomplish it but nothing happens: 我认为这是完成它的正确方法,但没有任何反应:
$("#search-btn").click(function{
$("controls-main").animate({
background: "red"
}, 500);
})
jQuery on its own can't animate colors. jQuery本身不能为颜色设置动画。 You need another library like jQuery UI. 你需要另一个像jQuery UI这样的库。 See this SO answer for more information. 有关更多信息,请参阅此SO答案 。
In the fiddle: 在小提琴:
Updated working fiddle: https://jsfiddle.net/9hcoy9j8/18/ 更新了工作小提琴: https : //jsfiddle.net/9hcoy9j8/18/
$(document).ready(function() {
$(".rand-wiki").click(function() {
window.open("https://en.wikipedia.org/wiki/Special:Random");
});
$(".s-form").on('click', function () {
$("[name=search]").animate({
marginTop: '40px'
}, 500);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.