The test environment is Firefox, IE is not measured.
Directly gives the result: the fastest is the function setcss (els,name,val) {} This method of setting style, the second is to change the class name, the slowest is CSS ()
Recommended simple operation style using the method, a large number of CSS, and to facilitate the user to make their own skin, it should be better to change the class name.
The code is as follows |
Copy Code |
Console.time ("Change class name"); $ ("P"). addclass ("a"); Console.timeend ("Change class name");
Console.time ("Use CSS ()"); $ ("P"). CSS ("Color", "red"); Console.timeend ("Use CSS ()");
Console.time (' style settings converted to JS '); /*var p = $ ("P"); var len = p.length; for (Var i=0;i<len;i++) { P[i].style.display = "block"; }*/ Setcss ("Li", "display", "none"); function Setcss (els,name,val) { var obj = $ (eLs); var len = obj.length; for (Var i=0;i<len;i++) { Obj[i].style[name] = val; } }
Console.timeend (' style settings converted to JS '); Console.time (' Convert to JS style setting 2 '); /*var p = $ ("P"); var len = p.length; for (Var i=0;i<len;i++) { P[i].style.display = "block"; }*/ Setcss ("Li", "display", "block"); function Setcss (els,name,val) { var obj = $ (eLs); var len = obj.length; for (Var i=0;i<len;i++) { Obj[i].style[name] = val; } } Console.timeend (' Convert to JS style setting 2 '); |