开发者

How do I make draggable divs with different functions?

I have four divs that are draggable. And a div where I drop the daggable divs. My code is basically just an API I've downloaded and modify a little form jQuery's sites.

My problem is that all the divs have the same function when they are dropped. How can I make individual functions to individual divs?

It looks like this:

$(function() {
$("#draggable").draggable({ revert: "invalid" });
$("#draggable2").draggable({ revert: "invalid" });
$("#draggable3").draggable({ revert: "invalid" });
$("#draggable4").draggable({ revert: "invalid" });

$("#droppable").droppable({
    activeClass: "ui-state-hover",
    hoverClass: "ui-state-active",
    drop: function(event, ui) {
        if (document.getElementById('draggable')){
            window.location.replace("http://www.example.com");      
            }
        if (document.getElementById('draggable2')){
            window.location.replace("http://www.example2.com");     
            }
        if (document.getElementById('draggable3')){
            window.location.replace("http://www.example3.com");     
            }
        if (document.getElementById('draggable4')){
            window.location.replace("http://www.example4.com");     
            }
        }
    });
});
开发者_如何学JAVA

No luck in this code. Any ideas?

Thanks in advance!

Regards, VG


In your 'if' statements you need to do something like:

if(ui.draggable.attr('id') === 'draggable')
{
    // do stuff
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜