2010-03-30 2 views
4

에 드래그 jQuery를 UI 나는이 http://jqueryui.com/demos/droppable/작은 낙하 할

을 사용하고 있습니다하지만이 문제를 드래그보다 작은 낙하 할에 끌어 있습니다.
droppable에는 드롭되지 않지만 droppable의 왼쪽 위에 나타납니다.

alt text http://yart.com.au/junk/draggableProblem.jpg

이 주변에 어떤 방법이 있나요?

다음은 코드입니다. 감사합니다.

$('.draggable').draggable({ 
    revert: 'invalid', 
    revertDuration: 500, 
    appendTo: 'body', 

    helper: function(event, ui) { 
     return $(this).clone().appendTo('body').css('zIndex', 5).show(); 
    }, 
    drag: function(event, ui) { 
     $(ui.helper).removeClass("enlarge"); 
     $(ui.helper).addClass("thumbnail"); 
     $(this).hide(); 
    }, 
    stop: function(event, ui) { 
     $(this).show(); 
     //$(this).addClass("enlarge"); 
     if ($(this).parent().hasClass("imageContainer")) { 
     $(this).addClass("thumbnail"); 
     } 
     else { 
     $(this).addClass("enlarge"); 
     } 
    }, 
    //cursorAt: { top: 30, left: 40 }, 
    delay: 100, 
    refreshPositions: true 
    }); 


    $('.imageContainer').droppable({ 
    accept: '.draggable', 
    drop: function(event, ui) { 
     ui.draggable.css({ 
     "position": "relative", 
     "left": "0px", 
     "top": "0px" 
     }); 
     if ($(this).children().length == 0) { 
     // ui.draggable.addClass("thumbnail"); 
     $(ui.draggable).appendTo(this); 
     $(this).removeClass("border"); 
     } 
    }, 
    over: function(event, ui) { 
     ui.draggable.removeClass("enlarge"); 
     ui.draggable.addClass("thumbnail"); 
     $(this).addClass("border"); 
    }, 
    out: function(event, ui) { 
     // ui.draggable.removeClass("zoomIn") 
     $(this).removeClass("border"); 
    }, 

    tolerance: 'intersect' 
    }); 

CSS :

.thumbnail { 
    height:60px; 
    margin-right:10px; 
    width:80px; 
    z-index:1; 
} 
.enlarge { 
    border:5px solid white; 
    height:145px; 
    width:195px; 
} 
+0

draggable 및 droppable에 대한 jquery 코드를 표시 할 수 있습니까? 나는 알고 있다고 생각하지만 대답은 내 마음 속으로 뛰어 오르지 않는다. – jcolebrand

+0

코드를 추가했습니다. 감사합니다. drachenstern – Aximili

+0

죄송합니다.이 글을 다시 읽지 못해 죄송합니다. 조금만 살펴보고 내가 도울 수 있는지 알아 보겠습니다. - 확대를 위해 CSS를 게시 할 수 있습니까? 및 미리보기 이미지? - 수업을 ui.helper에서 draluable로 혼자두면 어떻게됩니까? 예상대로 떨어지는가? (크기는 크더라도?) – jcolebrand

답변

3
$('.draggable').draggable({ 
    revert: 'invalid', 
    revertDuration: 500, 
    appendTo: 'body', 

    helper: function(event, ui) { 
     return $(this).clone().appendTo('body').css('zIndex', 5).show(); 
    }, 
    drag: function(event, ui) { 
    /* $(ui.helper).removeClass("enlarge"); 
     $(ui.helper).addClass("thumbnail"); */ 
     $(this).hide(); 
    }, 
    stop: function(event, ui) { 
     $(this).show(); 
     //$(this).addClass("enlarge"); 
     if ($(this).parent().hasClass("imageContainer")) { 
     $(this).addClass("thumbnail"); 
     } 
     else { 
     $(this).addClass("enlarge"); 
     } 
    }, 
    //cursorAt: { top: 30, left: 40 }, 
    delay: 100, 
    refreshPositions: true 
    }); 

위의이 블록에 코드를 교체 시도하고 당신이 원하는 것을 가까이 오면 참조하십시오. 아직 완벽하지는 않지만 한 번에 하나의 변화를 해결할 수 있는지 알아 봅시다. 내가 관찰하기를 바라는 것은 그것이 대략해야하는 것처럼 떨어지는 것입니다.

+0

감사합니다. 여기에 보고서가 있습니다. http://yart.com.au/junk/draggableProblem2.jpg ("Box Here"는 Droppable이있는 곳입니다) – Aximili

+3

"tolerance : 'pointer'대신 "tolerance : 'intersect'"- 이전 코드 변경으로 인해 발생하는 것에 대한 내 기대가 확인되었습니다. – jcolebrand

+0

그게 다야 !! 감사합니다 drachenstern! – Aximili