jQuery.css() - marginLeft vs. margin-left? [英] jQuery.css() - marginLeft vs. margin-left?

查看:608
本文介绍了jQuery.css() - marginLeft vs. margin-left?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用jQuery.css()我已经被告知我可以使用以下两个函数来获得相同的结果:

With jQuery.css() I've been told I can use the following two functions for the same results:

$(".element").css("marginLeft") = "200px";

$(".element").css("margin-left") = "200px";

我一直使用 marginLeft 是文档中使用的内容:

I've always used marginLeft as this is what is used in the documentation:

http://api.jquery。 com / css /


支持CSS属性(例如边距,背景,边框)不支持
。例如,如果要检索渲染的边距,
使用:$(elem).css('marginTop')和$(elem).css('marginRight'),因此

Shorthand CSS properties (e.g. margin, background, border) are not supported. For example, if you want to retrieve the rendered margin, use: $(elem).css('marginTop') and $(elem).css('marginRight'), and so on.

为什么jQuery允许 marginLeft 以及 margin-left ?这似乎毫无意义,并使用更多的资源转换为CSS margin-left

Why has jQuery allowed for marginLeft as well as margin-left? It seems pointless and uses more resources to be converted to the CSS margin-left?

推荐答案

jQuery的底层代码将这些字符串传递给DOM,这允许你以非常相似的方式指定CSS属性名称或DOM属性名称:

jQuery's underlying code passes these strings to the DOM, which allows you to specify the CSS property name or the DOM property name in a very similar way:

element.style.marginLeft = "10px";

等效于:

element.style["margin-left"] = "10px";




为什么jQuery允许marginLeft以及margin-left?它似乎毫无意义,并使用更多的资源转换为CSS边距 - 左?

Why has jQuery allowed for marginLeft as well as margin-left? It seems pointless and uses more resources to be converted to the CSS margin-left?

jQuery不是真的做什么特别的。它可以改变或代理你传递给 .css()的一些字符串,但实际上从jQuery团队中没有工作允许任何字符串传递。没有额外的资源使用,因为DOM做的工作。

jQuery's not really doing anything special. It may alter or proxy some strings that you pass to .css(), but in reality there was no work put in from the jQuery team to allow either string to be passed. There's no extra resources used because the DOM does the work.

这篇关于jQuery.css() - marginLeft vs. margin-left?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆