Bootstrap pop-up box (modal) Vertical center problem and Solution _javascript tips

Source: Internet
Author: User

People who have used bootstrap modal (modal box) components have a kind of confusion, so how can a good pop-up box not be centered vertically? Happen to do a EIT project, because some of the framework of this project to follow the nttdata of some rules, so the use of the bootstrap this Dongdong, the first encounter this dongdong, there is a lot of resistance, feel bad, but I think with the other pop-up box really no different. Talk less, cut to the chase, bootstrap the problem of vertical center, because the pop-up I got is not vertically centered, but top 10%, but the page is long, it seems particularly disgusting.

The solution looks like this:

1. In CSS, find

. modal.fade.in {
top:10%
}

This style, modify it OK, because the CSS is global, but also can be defined in the page to a modal (height) position, the following methods:

<style>
#myModal-help
{
top:300px
}
</style>

#myModal-help This is the modal ID, so the setting is OK.

2. In JS,

I'm using bootstrap-modal.js (if you're using a bootstrap.js or a bootstrap.min.js, you can, but you need to find the location).

Found in JS (red is the method I added):

var left = ($ (document.body). Width ()-that. $element. Width ())/2; 
 Console.log (left); 
$element 
. addclass (' in ') 
. attr (' Aria-hidden ', false) 
. css ({ 
left:left, 
top:top, 
Margin: "0 auto" 
});
That.enforcefocus ()

Once found, add the red to the OK, so that all the pop-up boxes are centered vertically.

The above is a small set to introduce the Bootstrap pop-up box (modal) vertical center of the problem and solution of the relevant knowledge, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.