javascript - Center a dynamic on screen -


I am trying to create a gallery-page as a list of thumbnails when a thumbnail is clicked The related picture opens in "popup" - the device shows the full size of the image.

The problem I have is focusing on that div on the screen. Each picture has different dimensions.

How to do this with Javascript / jQuery?

JSFiddle:

HTML:

  & lt; Div id = "pic1" class = "white_content" & gt; & Lt; img src = "https://scontent-a-fra.xx.fbcdn.net/hphotos-xap1 / v / t1.0-9 / 1378748_520568708029338_926300946_n.jpg Oh = d092e1f660360c84033f6144010052f9 & amp ;? i = 54F4B302" / & gt; & Lt; / Div & gt; & Lt; Div id = "pic2" class = "white_content" & gt; & Lt; Img src = "Https://skantent-a-frakshshkfbkdnknet/ःfotos-sfl/w/l/tlk0-9 /53942l_4l892236l527307_l534426043_nkjpg?oh=006a46697258683be3423d378cf40feb∓oa=54ABD335"/>< ; / Div & gt; & Lt; Div id = "fade" class = "black_overlay" & gt; & Lt; / Div & gt; & Lt; Div id = "wrapper" & gt; & Lt; Section id = "gallery" & gt; & Lt; Ul & gt; & Lt; Li style = "background image: urls ('https://scontent-a-fra.xx.fbcdn.net/hphotos-xap1/v/t1.0-9/1378748_520568708029338_926300946_n.jpg?oh=d092e1f660360c84033f6144010052f9&oe = 54F4B302' ); "& Gt; & Lt; a href = "javascript: void (0)" class = "gallerylink" onclick = "document.getElementById ( 'pic1') style.display = 'inline-block'; document.getElementById ( 'fade') style .. .display = 'Block' '& gt; & lt; / a & gt; & lt; / li & gt; & gt; li style = "background image: url (' https: //scontent-a-fra.xx.fbcdn .net / hphotos-xaf1 / v / l / t1.0-9 / 539421_418922361527307_1534426043_n.jpg? oh = 006a46697258683be3423d378cf40feb & amp; i = 54ABD335 '); "& Gt; & lt; a href =" javascript: void (0) "class =" gallerylink "onclick =" document.getElementById ('pic2') style.display = 'inline-block'; Document.getElementById ('Fade') style .. .display = 'block' '& gt; & Lt; / A & gt; & Lt; / Li & gt; & Lt; / Ul & gt; & Lt; / Section & gt; & Lt; / Div & gt;   

CSS:

  # Gallery {Text-align: center; Width: 100%; } # Gallery ul {display: block; Padding: 0; List style: none; Hidden flurry; } # Gallery ul li {display: inline-block; Vertical-alignment: top; Background-position: center; Background size: cover; Repeat Background: No Repetition; Width: 250px; Height: 250px; Margin: 2.5%; -max-boundary-radius: 5px; -WebKit-boundary-radius: 5px; Boundary-radius: 5px; / * Future proofing * / -khtml-border-radius: 5px; / * For older Konqueror Browser * / cursor: Indicator; .black_overlay {cursor: indicator; display none; Status: fixed; Top: 0%; Left: 0%; Width: 100%; Height: 100%; Background color: black; Z-index: 1001; -Moopness: 0.8; Opacity: .80; Filters: alpha (opacity = 80); }. White_content {status: absolute; Top: 50%; Left: 50%; display none; Margin: 0 auto; Limit: 8px solid orange; Background-color: #EE; Z-index: 1002; } .gallerylink {display: block; Height: 100%; Width: 100%; Text-decoration: None; } << Code>   

You can get it by adding transform: translate (- 50%, -50%); , left: 50%; and Top: 50%; to .white_content like this:

JSFiddle -

  .white_content {status: absolute ; display none; Margin: 0 auto; Limit: 8px solid orange; Background-color: #EE; Z-index: 1002; Left: 50%; Top: 50%; Conversions: Translation (-50%, -50%);   

To remove the location given below, vertical-align: center in your images; should be added -

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -