Can someone help me understand what the next line means? What is -
elem,.style.height = ( pos /100) * h + "px";
There's a com开发者_如何学Pythonma right after elem.
function slideDown( elem ){
//
elem.style.height = '0px';
show(elem);
var h = fullHeight(elem);
for (var i = 0 ; i <= 100; i+= 5){
(function(){
var pos = i;
setTimeout(function(){
elem,.style.height = ( pos /100) * h + "px";
}, (pos + 1) * 10 );
})();
}
}
But let's explain the comma punctuator in JavaScript, shall we? :)
The comma can be either a separator or an operator. As a separator, it appears in these scenarios:
function foo(x, y, z) { /* function body */ }
foo(1, 2, 3);
var obj = { name: "John", surname: "Smith", age: 35 };
var arr = [1, 2, 3];
var x = 1, y = 2, z = 3;
This is not a complete list, but I think I covered the most popular scenarios (separating formal parameters in function declarations/expressions, arguments in function calls, object literal items, array literal items, and variable declarations).
As a operator, the comma can be used to list expressions:
x = 1, foo(), location.href, bar(), x = 2;
The comma operator should be avoided (" except for very disciplined use in the control part of for statements" - Crockford, http://javascript.crockford.com/code.html)
It is a typo, but it's also almost valid syntax.
The comma may be used to separate statements, returning the last. So this is valid:
a = 3;
a, b = 4;
However, the .style
in the second clause of the comma is invalid syntax (vars cannot begin with period, and style is not defined, so it can't have the property of height).
Remove the comma.
A comma will have the role of operator outside a string. Your example is clearly a mistake.
You can use the comma operator when you want to include multiple expressions in a location that requires a single expression. The most common usage of this operator is to supply multiple parameters in a for loop.
Source: MDC
精彩评论