2015-10-01 168 views
1

我有一個拖放位置,我想隱藏掉落的圖像。我的問題是,圖像都有相同的class和隱藏的class滴隱藏所有的圖像,包括那些還沒有被丟棄。我嘗試了$(this).Hide();,但是這隱藏了droppabble而不是拖動的圖像。隱藏掉落的元素

代碼的圖像:

using (The_Factory.Models.The_FactoryDBContext db2 = new The_Factory.Models.The_FactoryDBContext()) 
       { 

        string imageSource = ""; 

        av = db2.Letter_Activity.ToList().FirstOrDefault(a => a.name == qs); 

        for (int i = 0; i < 4; i++) 
        { 

         if (av != null) 
         { 
          string imageBase = Convert.ToBase64String(av.image); 
          imageSource = string.Format("data:image/gif;base64,{0}", imageBase); 


          <img src="@imageSource" class="draggable correct" id="@av.name"/> 

         } 
        } 
       } 

這是代碼爲我投擲的

$("#droppable").droppable({ 
     accept: '.correct', 
     drop: function (event, ui) { 
      $(".correct").hide(); 
    }); 

    $("#playAgain").click(function() { 
     location.reload(true); 
    }); 
}); 

回答

0

元素拖是通過ui參數作爲ui.draggable訪問。

$("#droppable").droppable({ 
     accept: '.correct', 
     drop: function (event, ui) { 
      ui.draggable.hide(); // hide the element dragged... 
    }); 

    $("#playAgain").click(function() { 
     location.reload(true); 
    }); 
}); 
0

一類添加到元素時,它被DROP掉。

$("#droppable").droppable({ 
     accept: '.correct', 
     drop: function (event, ui) { 
      $(this).addClass("dropped"); 
      $(".dropped").hide(); 
    }); 

    $("#playAgain").click(function() { 
     location.reload(true); 
    }); 
}); 

它可能是更好的隱藏.dropped類CSS

.dropped{display:none;} 
+0

在此上下文中的'this'引用是指可放下的。所以不是隱藏圖像而是隱藏可丟棄圖像。 –