Note that there are some explanatory texts on larger screens.

plurals
  1. POJquery + zindex increment
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/12665435/jquery-draggable-bring-to-front">Jquery Draggable + Bring to Front</a> </p> </blockquote> <p>I have a site where users can open a number of chat windows.</p> <p>I need to keep the latest window on top and I'm using the following</p> <pre><code> var chatZIndex = 100; $(document).on('mousedown','div.chatMessenger', function() { $(this).css('z-index', chatZIndex++); }); </code></pre> <p>This works fine but I have found one bug. If there are 6 chat boxes open (6 instances of 'div.chatMessenger') then the variable chatZIndex increments by 6 at a time. 4 open and then increments by 4 etc etc.</p> <p>Is there a way to use this same setup but only have the variable increment by 1 at a time regardless of how many instances of 'div.chatMessenger' are open?</p> <p>thx</p> <hr> <p>this is the current code to set them up</p> <pre><code>var memberID = 1000000000; // This is the Member ID - REPLACE var chatMsgTop = 45; // Initial Chat Open Location Top var chatMsgLeft = 45; // Initial Chat Open Location Left var chatZIndex = 100; // Starting Number for Chat Messenger z-index Value // Chat Messenger - Open a New Chat Messager IM Box $(document).on('click','div#chatFriendsContainer table tr', function() { memberID++; // This is the Member ID - REPLACE // Increment Initial Chat Messaging Location on Windows - Avoid Overlap chatMsgTop += 10; chatMsgLeft += 10; var timeStamp = Math.round((new Date()).getTime() / 1000); // Timestamp $('div#chatWrapper').append('&lt;div id="'+memberID+'" class="chatMessenger" data-timestamp="'+timeStamp+'"&gt;&lt;/div&gt;'); // Create new Chat IM Container $('div#chatMessengerTemplate div.chatMessengerContainer').clone().appendTo('div#'+memberID); // Clone Template $('div#'+memberID).css({left : chatMsgLeft+'px', top : chatMsgTop+'px'}); // Update IM Location // JQUERY UI Draggable - Initialize $('div#'+memberID).draggable({ containment: $('div#chatWrapper') }); // JQUERY UI Draggable - Update Z-Index $(document).on('mousedown','div.chatMessenger', function() { //$('div.chatMessenger').not(this).css('z-index', '100'); //alert('here now...'); if($('div.chatMessenger', this)) { $(this).css('z-index', chatZIndex++); } }); </code></pre>
    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.
 

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