向可拖动对象添加颜色

Adding Color to a Draggable

本文关键字:添加 颜色 对象 拖动      更新时间:2023-09-26

如何添加具有特定颜色(例如蓝色)的可拖动对象?

我一直在使用

<script type="text/javascript">
        $( function() {
            $( ".box" ).draggable({containment: "parent"});
            $( ".box" ).css("background-color","blue");
        });
    </script>

但它的颜色没有变化,因为它保持白色。还有,为什么会发生这种情况?

var color = function(color){
  //processing here
return color;
}
        $( function() {
            $( ".box" ).draggable({containment: "parent"});
            $( ".box" ).css("background-color",color("whatever"));
        });

您可以在color函数中添加某种类型的逻辑,以根据需要更改该颜色