mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
docs(compiler): fix variable scope in drag sample
Note that without this fix, if you add a second draggable element, the two instances clobber each other since there is only one set of startx/starty/x/y variables. Here is an example: http://plnkr.co/edit/aGrLXcIo2SuaePuAdfmQ?p=preview. On the surface it looks like it would be fine because you only have one mouse but in practice the start position jumps when you start dragging. Here it is fixed: http://plnkr.co/edit/VuvPasuumtCeiVRisYKQ?p=preview
This commit is contained in:
parent
2d66ccd593
commit
8c75b5f55a
1 changed files with 1 additions and 1 deletions
|
|
@ -70,8 +70,8 @@ Here is a directive which makes any element draggable. Notice the `draggable` at
|
|||
<file name="script.js">
|
||||
angular.module('drag', []).
|
||||
directive('draggable', function($document) {
|
||||
var startX=0, startY=0, x = 0, y = 0;
|
||||
return function(scope, element, attr) {
|
||||
var startX = 0, startY = 0, x = 0, y = 0;
|
||||
element.css({
|
||||
position: 'relative',
|
||||
border: '1px solid red',
|
||||
|
|
|
|||
Loading…
Reference in a new issue