Jquery/Draggable/Background window to the foreground with a mouse click /How?
I use the stack option to get the background windows to the the foreground by dragging. But I am stacked when I want to get a window in the foreground by clicking. I couldn't figure out how to get the largest z-index.
EDIT:
$('.drag').draggable({stack: '.drag'}
This code brings the bac开发者_开发百科kground div.drag
in the foreground, but just if you drag it. I want the background div.drag
to get into the foreground also when you click it. If you just click it it stays int the background.
EDIT 2:
Meanwhile I used:
var zIndex = $('.drag').length;
$('.drag').draggable({stack: '.drag'},
stop: function() {
zIndex = $(this).css('z-index');
}
}).click(function(event){
$(this).css('z-index', ++zIndex);
});
I would do this the same way jQueryUI does (unfortunately I couldn't figure out a way to manually trigger this method):
$(".drag").draggable({
stack: ".drag"
}).bind("click", function() {
var o = $(this).data("draggable").options;
var group = $.makeArray($(o.stack)).sort(function(a, b) {
return (parseInt($(a).css("zIndex"), 10) || 0) - (parseInt($(b).css("zIndex"), 10) || 0);
});
if (!group.length) {
return;
}
var min = parseInt(group[0].style.zIndex) || 0;
$(group).each(function(i) {
this.style.zIndex = min + i;
});
this.style.zIndex = min + group.length;
});
Here's a working example: http://jsfiddle.net/andrewwhitaker/uYpnW/2/
Hope that helps!
精彩评论