这个javascript无法脱机工作

时间:2017-03-18 15:04:30

标签: javascript html css

我正在使用像Win7 Sidebar这样的javascript制作小工具系统,但这在FILE协议中不起作用。我正在使用的浏览器是Chrome。 如何使其脱机工作?

var selected = null, // Object of the element to be moved
    x_pos = 0, y_pos = 0, // Stores x & y coordinates of the mouse pointer
    x_elem = 0, y_elem = 0; // Stores top, left values (edge) of the element

// Will be called when user starts dragging an element
function _drag_init(elem) {
    // Store the object of the element which needs to be moved
    selected = elem;
    x_elem = x_pos ;
    y_elem = y_pos;
}

// Will be called when user dragging an element
function _move_elem(e) {
    x_pos = document.all ? window.event.clientX : e.pageX;
    y_pos = document.all ? window.event.clientY : e.pageY;
    if (selected !== null) {
        selected.style.left = (x_pos - x_elem) + 'px';
        selected.style.top = (y_pos - y_elem) + 'px';
    }
}

// Destroy the object when we are done
function _destroy() {
    selected = null;
}

// Bind the functions...
var draggables = document.getElementsByClassName('draggable-element');
for(var i = 0; i < draggables.length; i++){
  draggables[i].onmousedown = function () {
      _drag_init(this);
      return false;
  };
}

document.onmousemove = _move_elem;
document.onmouseup = _destroy;
body {padding:10px}

.draggable-element {
  width:125px;
  height:125px;
  background-color:#666;
  color:white;
  padding:10px 12px;
  cursor:move;
  position:relative; /* important (all position that's not `static`) */
}
<div class="draggable-element">Gadget!<div style="width:20px;height:100%;background:#000;position:absolute;top:0;right:-25px"></div></div>
<div class="draggable-element">Gadget!<div style="width:20px;height:100%;background:#000;position:absolute;top:0;right:-25px"></div></div>
<div class="draggable-element">Gadget!<div style="width:20px;height:100%;background:#000;position:absolute;top:0;right:-25px"></div></div>
<div class="draggable-element">Gadget!<div style="width:20px;height:100%;background:#000;position:absolute;top:0;right:-25px"></div></div>
<div class="draggable-element">Gadget!<div style="width:20px;height:100%;background:#000;position:absolute;top:0;right:-25px"></div></div>
<div class="draggable-element">Gadget!<div style="width:20px;height:100%;background:#000;position:absolute;top:0;right:-25px"></div></div>

谁能提供帮助,请提前谢谢。

1 个答案:

答案 0 :(得分:0)

{{ url_for('folder'), filename = 'subfolder/some_image.jpg' }}函数替换为: _move_elem

_move_elem

我认为减去这个位置就是把它扔掉,把它放回去。我也使用文件uri,它的工作原理。希望这可以帮助! 编辑:Codepen在http://codepen.io/JohnJ1101/pen/oZpwGv