Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery SlideDown with dynamically fixed center
    primarykey
    data
    text
    <p>I'm writing my own popUp function in jQuery. I get the width and height dynamically and then slide down the element after a click event.</p> <p>But unfortunately after I wrote the part that determines the height and with and sets the center css, the slideDown function now makes the element appear in the center of the page and grow in the up and down direction simultaneously, instead just folding it down from the top.</p> <p>The main source of the problem should be the <code>margin-top</code>, I guess.</p> <p>Do you know how to fix this?</p> <p>Here is my code:</p> <p>HTML:</p> <pre><code>&lt;div class="container"&gt; &lt;div id="Portfolio"&gt; &lt;div id="PortfolioGrid"&gt; &lt;div class="overlay"&gt;overlay&lt;/div&gt; &lt;div class="popup"&gt; &lt;div class="close" style="display: none;"&gt; &lt;i class="icn-x"&gt;&lt;/i&gt; &lt;/div&gt; &lt;dl class="beschreibung"&gt; &lt;dt&gt;Beschreibung&lt;/dt&gt; &lt;dd&gt;xsssxxsxsxsxssxsxsx&lt;/dd&gt; &lt;dt&gt;Aufgabe&lt;/dt&gt; &lt;dd&gt;dsfgfdgfgdf&lt;/dd&gt; &lt;dt&gt;Kunde&lt;/dt&gt; &lt;dd&gt;Bla&lt;/dd&gt; &lt;/dl&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p></p> <p>CSS:</p> <pre><code>.container { width: 250px; } .popup { display: none; } .popup.clone { display: none; z-index: 5002; position: fixed; top: 50%; left: 50%; background-color: #fff; border: 1px solid #ccc; } .beschreibung { background-color: #fff; } </code></pre> <p>jQuery:</p> <pre><code>$("#Portfolio").on("click", ".overlay", function() { var popup_state_port = false; if(popup_state_port == false) { var klon = $(this).nextAll('.popup').clone(); $(klon).addClass('clone'); $('#PortfolioGrid').after(klon); var width = $('.container').width(); var height = $('.clone').height(); //console.log(width); $('.clone').css({ 'width': width, 'margin-left': -width/2, 'margin-top': -height/2 }) $('.clone').slideDown("normal", function() { $(this).find('.close').fadeIn(); }); $(".bg").css("opacity", "0.7"); $(".bg").fadeIn("normal"); popup_state_port = true; } return false; }); </code></pre> <p>and a FIDDLE, so that you can see the effect: <strong><a href="http://jsfiddle.net/27dBE/" rel="nofollow">FIDDLE</a></strong></p> <p>Thank you!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload