1

我有一个应该是可拖动的 div。下面是代码,

$( "#SpeedDraggable" ). draggable
({
    axis: "y",
    containment:'parent',
        drag: function(event, ui)
        {
           var Startpos = $(this).position();
           $("#SpeedText").text(184-Startpos.top).css('color','#DDDDDD');              
        },
    stop: function(event, ui) 
    {
       var Stoppos = $(this).position();
       $("#SpeedText").text(184-Stoppos.top).css('color','#DDDDDD');
    }
    });

要求是上述逻辑应该在这个if条件下发生

if($("#imgManualSetting_Pressed").is(":visible"))
{

}

如果这个条件不成立,那么 div 不应该是可拖动的。请帮助我如何做到这一点......提前谢谢!

4

2 回答 2

2
$( "#SpeedDraggable" ). draggable
({
    axis: "y",
    containment:'parent',
    drag: function(event, ui)
    {
        if($("#imgManualSetting_Pressed").is(":visible"))
        {
            var Startpos = $(this).position();
                $("#SpeedText").text(184-Startpos.top).css('color','#DDDDDD');  
        }
        else
       {
                return false;            
       }                    
    }

});
于 2013-02-19T05:52:49.300 回答
1
if($("#imgManualSetting_Pressed").is(":visible")) {
    // set to draggable widget
    $( "#SpeedDraggable" ).draggable({
        axis: "y",
        containment:'parent',
            drag: function(event, ui)
            {
               var Startpos = $(this).position();
               $("#SpeedText").text(184-Startpos.top).css('color','#DDDDDD');              
            },
        stop: function(event, ui) 
        {
           var Stoppos = $(this).position();
           $("#SpeedText").text(184-Stoppos.top).css('color','#DDDDDD');
        }
    });
}
else {
    // destroy draggable if not
    $( "#SpeedDraggable" ).draggable( "destroy" );
}
于 2013-02-19T05:31:00.123 回答