当我放下边框时,如何让边框变回黑色,如何确保它不会离开屏幕?

时间:2017-11-03 01:51:11

标签: javascript html css

现在,当我点击它并且它变成绿色时,我的div会移动,但是当我不再拖动它时,我无法弄清楚如何让它变回黑色。另外,我如何确保它不会离开屏幕?

class A
  has_many :B, -> { ... where clause 1 }, source: :tags
  has_many :C, -> { ... where clause 2 }, source: :tags
end

2 个答案:

答案 0 :(得分:0)

到边框颜色:

obj.onmouseup = function(){
        dragObj = null;
        obj.style.borderColor = "#000";
}

到屏幕限制:

I don't know.

答案 1 :(得分:0)

将您当前的代码更改为此。

obj.onmousedown = function(){
    dragObj = obj;
    obj.style.border-color = "#000000";
}

document.onmousemove = function(e){
    var x = e.pageX;
    var y = e.pageY;

    if (x < 0) x = 0;
    if (x > window.innerWidth) x = window.innerWidth;
    if (y < 0) y = 0;
    if (y > window.innerHeight) y = window.innerHeight;

    if(dragObj == null)
        return;

    dragObj.style.left = x +"px";
    dragObj.style.top= y +"px";
};