3

我有一个可拖动的 div,当我拖动 div 时,无法弄清楚如何删除右侧或底部的 CSS 规则。

css

#draggablediv
{
    right:25%;/*delete this when i begin to drag*/
    bottom:25%;/*delete this when i begin to drag*/
}

非常感谢。

$('#message2').draggable({handle: "#draghand", containment: "#drag_border", scroll:    false },{
    start: function() {
      // alert('started');
      $(this).css({
        "right": " ",
        "bottom": " "});
    }
  });

这是我使用的功能,但我似乎不起作用......我放火但属性不受影响的警报

4

1 回答 1

2

You aren't passing in a value so the code isn't going to change it back for you. The code you need is:

$('#message2').draggable({handle: "#draghand", containment: "#drag_border", scroll: false },{
    start: function() {
      // alert('started');
      $('#draggablediv').css({
        "right": "auto",
        "bottom": "auto"});
    }
});

This resets the bottom and right back to their default properties.

Alternately, put the right and bottom styles in a class that you apply to the div:

.not-dragging
{
    right:25%;/*delete this when i begin to drag*/
    bottom:25%;/*delete this when i begin to drag*/
}

...and remove that class when you start dragging:

$('#message2').draggable({handle: "#draghand", containment: "#drag_border", scroll: false },{
    start: function() {
      // alert('started');
      $('#draggablediv').removeClass("not-dragging");
    }
});
于 2013-07-16T17:45:17.833 回答