JQuery in the CSS method for floating

Source: Internet
Author: User

In JavaScript, you set the floating properties of elements (float), and standard browsers use CSS tutorials to float,ie older versions using Stylefloat. This uses $ (xx). CSS ("Cssfloat", "right") or $ (xx). CSS ("stylefloat", "right") all browsers are OK

jquery's CSS method unifies two kinds of writing, uses the float attribute directly, the following CSS method passes the parameter "float" to be able to set up also can obtain the element float.

<div id= "D1" >float div</div>
<script type= "text/web Effects" >
$ (' #d1 '). css (' float ', ' right ');
var str = $ (' #d1 '). css (' float ');
alert (str);
</script>

But jquery has to be smart, plus support for cssfloat and stylefloat, see API documentation, like getting the float property of an element, the following is equivalent.

1 $ (' Div.left '). css (' float ');

2 $ (' Div.left '). CSS (' cssfloat ');

3 $ (' Div.left '). CSS (' stylefloat ');

But mode 3 returns different values in each browser, such as using stylefloat to get floating

<div id= "D1" >float div</div>
<script type= "Text/javascript" >
Alert ($ (' #d1 '). CSS (' stylefloat ');
</script>

IE6/7/8: Setup was unsuccessful

Ie9/10/firefox/safari/chrome/opera: Set Success

Also, use stylefloat to set the float:

<div id= "D1" >float div</div>
<script type= "Text/javascript" >
$ (' #d1 '). CSS (' stylefloat ', ' right ');
</script>

This uses $ (xx). CSS ("stylefloat") there is no compatibility problem.

2, modify the Jquery.style method, add a judgment if Stylefloat or cssfloat are converted to float

Don ' t set styles on text and comment nodes
if (!elem | | elem.nodetype = = 3 | | elem.nodetype = 8 | |!elem.style) {
Return
}

This is the plus fix code.

if (name = = = "Cssfloat" | | | name = = "Stylefloat") {
 name = "float"
}
//Make sure T Hat we ' re working with the right name
var ret, type, OrigName = jquery.camelcase (name),
 style = ELEM.S Tyle, hooks = jquery.csshooks[OrigName];
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.