I think I was thinking that. I came up with:
Code:
<!DOCTYPE html>
<html>
<head>
<title>Drag w/zIndex II</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>div.squares{display:block; width:125px; height:125px; }</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
jQuery(function($){
var sqs = $("div.squares").draggable().mousedown(function(){
sqs.css({zIndex: function(){
return Math.max(--this.style.zIndex, 0);
}
});
$(this).css({zIndex: 10000});
});
});
</script>
</head>
<body>
<div class="squares" style="background-color:#fcc;"></div>
<div class="squares" style="background-color:#ccc;"></div>
<div class="squares" style="background-color:#ffc;"></div>
</body>
</html>
I used 10000 because if it's less - say 10, it only takes 10 drags of the first one to lower the stack of the second one if it were already on top of the third one. But you know, draggable() has it's own events. So you could do the same with this monstrous one liner (doesn't have to be all one line):
Code:
<!DOCTYPE html>
<html>
<head>
<title>Drag w/zIndex III</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>div.squares{display:block; width:125px; height:125px; }</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>
<script>
jQuery(function($){
var sqs = $("div.squares").draggable({start: function(){sqs.not($(this).css({zIndex: 10000})).css({zIndex: function(){return Math.max(--this.style.zIndex, 0);}});}});
});
</script>
</head>
<body>
<div class="squares" style="background-color:#fcc;"></div>
<div class="squares" style="background-color:#ccc;"></div>
<div class="squares" style="background-color:#ffc;"></div>
</body>
</html>
But I think that might be less efficient.
See also:
http://jqueryui.com/demos/draggable/
particularly:
http://jqueryui.com/demos/draggable/#events
Bookmarks