0

I have 3 draggables and I want them to fit in one droppable each, when they have all been dropped I'd like to do something... I don't know if this code is very good but I don't know how to do it in any other way. Now I wonder if anyone can help me... Guess you can see that I'm very new to this, here is my .js Should I make some kind of array to count the droppables?

$(function(){

    $("#dragItems img").draggable({
        containment: "#gameBoard",
        revert: "invalid"
    });



    var i = 0;
    $(function(){

            if(i === 2){
                //do something;
            } else {
                $("#dropBoxes img#drop4").droppable( { 

                    tolerance : "intersect",
                    accept : "img#drag4",
                        drop : function() {
                            $(this).append("<embed src='button-1.wav' autostart='true' hidden='true' loop='false'>");
                            i++;
                        }
                });
                $("#dropBoxes img#drop5").droppable( { 

                    tolerance : "intersect",
                    accept : "img#drag5",
                        drop : function() {
                            $(this).append("<embed src='button-1.wav' autostart='true' hidden='true' loop='false'>");
                            i++;
                        }
                });
                $("#dropBoxes img#drop2").droppable( { 

                    tolerance : "intersect",
                    accept : "img#drag2",
                        drop : function() {
                            $(this).append("<embed src='button-1.wav' autostart='true' hidden='true' loop='false'>");
                            i++;
                        }
                });
            }


    });
});
4

1 回答 1

0

你想在跌落发生后做点什么……对吧?

在您拥有的所有地方i++,为什么不让下一行调用一个函数来检查 的值i并做任何需要做的事情。

例子:

          $("#dropBoxes img#drop2").droppable( { 

                tolerance : "intersect",
                accept : "img#drag2",
                    drop : function() {
                        $(this).append("<embed src='button-1.wav' autostart='true' hidden='true' loop='false'>");
                        i++;
                        //call my magical function that will do stuff
                        //magical_function(i);
                    }
            });

——还有你的神奇功能:

           function magical_function(i){
             if(i==2){//do something}
           } 
于 2014-03-27T17:50:47.560 回答