开发者

Jquery/Draggable/Background window to the foreground with a mouse click /How?

开发者 https://www.devze.com 2023-02-14 13:41 出处:网络
I use the stack option to get the background windows to the the foreground by dragging. But I am stacked

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!

0

精彩评论

暂无评论...
验证码 换一张
取 消