Why do Multiple Calls to jQuery UI Position Result in Different Placement? -


i have odd issue when using jquery ui position div. calling function first time places div in expected location. subsequent calls place div further , further right , bottom of window. below least amount of code reproduce problem with.

<!doctype html> <html> <head>     <title>jquery ui position test </title>     <script src="http://code.jquery.com/jquery-1.8.3.js"></script>     <script src="http://code.jquery.com/ui/1.10.2/jquery-ui.js"></script>     <style type="text/css">         #header {             height: 100px;             background: orange;         }          #content {             height: 300px;             background: blue;         }          #message {             width: 300px;             background: yellow;             position: absolute;             display: none;         }     </style> </head>  <body>     <div id="header"></div>     <div id="message">a message user</div>     <div id="content">         <input id="showmessagebutton" type="button" value="show message" />     </div>      <script>         $(document).ready(function () {             $('#showmessagebutton').bind("click", function () {                 $('#message').position({ my: "center top", at: "center bottom-12", of: "#header" });                 $('#message').fadein(800).delay(1000).fadeout(1000);             });         });     </script> </body> </html> 

if run code first time this, expected.

screen shot 1 http://www.michaelware.net/outsideimages/jquerypositionissue/screen1.png

after second call

screen shot 2 http://www.michaelware.net/outsideimages/jquerypositionissue/screen2.png

after third call

screen shot 3 http://www.michaelware.net/outsideimages/jquerypositionissue/screen3.png

please note have let fadein/fadeout finish or problem not occur.

two things. first .bind() has been deprecated in favor of .on(). second, need change order of calls to:

$('#showmessagebutton').on("click", function () {     $('#message').fadein(800).position({         my: "center top",         at: "center bottom-12",         of: "#header"     }).delay(1000).fadeout(1000); }); 

jsfiddle example

as docs position state, "note: jquery ui not support positioning hidden elements". since trying use position on hidden element, need make visible first. can witness if don't totally fade element out in this example using format of original code.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -