我得到了一个大小未知的元素,其中position = absolute,top = 1000,left = 1000.
现在,该元素的左上角位于(1000,1000),但我希望元素的中心为(1000,1000).
有没有办法单独使用CSS?
我有一段代码,有很多if和else if.我现在只想到,在乘法中,true计算结果为1,false计算结果为0.是否安全且更容易阅读(因为它更短)替换:
if(!this._isFetched('studentInfoFetched')) {
tempAddedTime += 1;
estimatedTimePerStudent += 0.04 + 0.2;
}
if(formInputValues.student_expiration){
tempAddedTime += (!this._isFetched('studentExpirationFetched'))? 14 : 0;
estimatedTimePerStudent += 1;
}
Run Code Online (Sandbox Code Playgroud)
用于:
tempAddedTime += 1 * (!this._isFetched('studentInfoFetched')) + 14 * (!this._isFetched('studentExpirationFetched')) * (formInputValues.student_expiration);
estimatedTimePerStudent += 0.24 * (!this._isFetched('studentInfoFetched')) + 1 * (formInputValues.student_expiration);
Run Code Online (Sandbox Code Playgroud)
注意:_isFetched返回一个bool.这只是一个例子,对于其他情况我还有更多,如果这样可以节省更多的线.