Skip to content

Instantly share code, notes, and snippets.

@aurbano
Last active August 18, 2016 15:39
Show Gist options
  • Save aurbano/9ce7e689d8138f341aea to your computer and use it in GitHub Desktop.
Save aurbano/9ce7e689d8138f341aea to your computer and use it in GitHub Desktop.
jQuery Draggable bring to front
<script type="text/javascript">
$('.drag').bind('click',function(){ bringFront($(this), '.drag'); });
</script>
function bringFront(elem, stack){
// Brings a file to the stack front
var min, group = $(stack);
if(group.length < 1) return;
min = parseInt(group[0].style.zIndex, 10) || 0;
$(group).each(function(i) {
this.style.zIndex = min i;
});
if(elem == undefined) return;
$(elem).css({'zIndex' : min group.length});
}
@ishanmitra
Copy link

Couple of sections where operators are missing, I added the + sign and works like charm.
Browser threw errors at Lines 8 and 12. Also I changed from 'click' to 'mousedown', the result being that your code would not change the z-Index until I released the mouse button, but this one does.
Commend your JS script, saved me a lot of headaches!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment