Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在jquery函数中应用css属性_Javascript_Jquery_Css - Fatal编程技术网

Javascript 在jquery函数中应用css属性

Javascript 在jquery函数中应用css属性,javascript,jquery,css,Javascript,Jquery,Css,我的代码有一些错误。也许有人能帮我。我得到这个错误: SyntaxError:缺少形式参数:$(this).css(“位置”、“相对”) $(文档).keydown(函数(e){ var计数=0; 如果(e.keyCode==40){ 计数++; } 如果(计数=1){ $(“#框”)。设置动画({ 边界间距:-90 }, { 步骤:函数(现在,fx){ $(this).css('-webkit transform','rotate('+now+'deg'); $(this.css('-moz

我的代码有一些错误。也许有人能帮我。我得到这个错误:

SyntaxError:缺少形式参数:$(this).css(“位置”、“相对”)

$(文档).keydown(函数(e){
var计数=0;
如果(e.keyCode==40){
计数++;
}
如果(计数=1){
$(“#框”)。设置动画({
边界间距:-90
}, {
步骤:函数(现在,fx){
$(this).css('-webkit transform','rotate('+now+'deg');
$(this.css('-moz transform','rotate('+now+'deg');
$(this.css('transform','rotate('+now+'deg');
},
持续时间:“慢”
}“线性”);
}否则{
$(“#框”)。设置动画({
身高:“10%”
}, {
$(this.css(“位置”、“相对”);
$(this.css(“页边距顶部”、“100px”);
$(this.css(“宽度”,“30%”);
$(this.css(“背景色”、“番茄”);
$(this.css(“左边距”、“20%”);
$(this.css(“对齐内容”、“中心”);
});
}
});

如果API使用方法错误,请将函数用作的第二个参数,它将正常工作

请尝试以下方法:

$('#box').animate({
  height: '10%'
}, function() {
  $(this).css("position", "relative");
  $(this).css("margin-top", "100px");
  $(this).css("width", "30%");
  $(this).css("background-color", "tomato");
  $(this).css("margin-left", "20%");
  $(this).css("align-content", "center");
});

jQuery.fn.animate的最后一个参数应该是函数。如果你需要的话

$(selector).animate({...styles...}, time, easing, function(){ /* callback */})
另外,您还可以使用一个对象同时设置所有css属性

$(this).css({
位置:'相对',
marginTop:'100px',
宽度:“30%”,
背景颜色:“西红柿”,
保证金金额:20%,
对齐内容:“中心”

})
如果错过了匿名函数包装器,请检查doct
jQuery.fn.animate
的第二个参数应该是functionStrange错误消息。jQuery的API与此无关。不知何故,它将该参数误认为是一个格式错误的函数。也许使用arrow函数语法,它认为那是主体,第一个参数是参数列表?
animate
的第二个参数可以是一个选项对象,但是一个对象不能只包含这样的jquery对象,然后它突然变成了没有对象键和属性的括号。您可能想将该代码放在回调函数中,您是否熟悉该功能(使用类似JSON的对象设置多个css变量)<代码>$(this.css({“position”:“relative”,“margin top”:“100px”,…})它会更干净-事实上,它是完全有效的,第二个参数是object,但是OP没有object,它只是两个括号,充满了废话。我对它很熟悉,但我的目标是帮助解决这个问题,而不是提供关于代码改进的反馈,因为这肯定更适合代码审查站点。