Js cannot obtain the width of the hidden div. It can only display the width first and then obtain the _ javascript technique.

Source: Internet
Author: User
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 "});
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.