Js cannot obtain the width of the hidden div. The current method is to display it first, then obtain its width and calculate the position. For the following example, you can refer
Var tipsWidth = $ (". loading ").css (" width "). replace ("px", "") // obtain var 1_wwidth =$ (window) first ). width (); $ (". loading "cmd.css ({" display ":" block "}); // display $ (". loading "cmd.css ({" left ": (required wwidth-tipsWidth)/2 +" px "});
I want to get the actual width of p Based on the adaptive width of the content. This p is hidden at first. I want to get the actual width of it and center it for a long time, the actual width of the p is always not obtained. Later, it was found that js cannot obtain the width of the hidden p. The current method is to display it first, then obtain the width and calculate the position.
$ (". Loading "cmd.css ({" display ":" block "}); // display var tipsWidth = $ (". loading ").css (" width "). replace ("px", "") // obtain var rewrite wwidth =$ (window ). width (); $ (". loading "cmd.css ({" left ": (required wwidth-tipsWidth)/2 +" px "});