JavaScript allow ng-drag element to be dragged in one direction only allow drag div,html5 allow drag element

I am using https://github.com/fatlinesofcode/ngDraggable.

<div  ng-drag="true" 
ng-drop="true" ng-drag-start="example($data,$event)"  >
</div>

The div is to be dropped right there where is was dragged from and it works just fine. However, I want it to be dragged in y direction only.

How do I do this?Using additional custom directive?Function? controller?

Also, I want the element to be dragged upto a maximum distance based on size of the screen may be, how do I add this constraint?

I found this https://github.com/fumitoito/angular-draggable but I need it to come back when it is dropped anywhere else except for drop area which is none in my case and It does not help with coming back thing.

Answer:1

Even if this is a somewhat old thread, I had the same requirement and finally resorted to modifying ngDraggable.js. For me the change was simple. The left position of the element to drag is always 0, so I only changed the lines that set the _tx variable in the onmove and onlongpress functions in the ngDrag directive:

if (_centerAnchor) {
    _tx = 0; // _tx = _mx - element.centerX - _dragOffset.left;
    _ty = _my - element.centerY - _dragOffset.top;
} else {
    _tx = 0; //_mx - _mrx - _dragOffset.left;
    _ty = _my - _mry - _dragOffset.top;
}

If you use ng-drag-clone you'll need to make a similar change in the onDragMove function as well.

Answer:2

I have an issue with the following code. I want to replace a string by another one, and generate an img code. However, I got an error message: str.replace is not a function. Any idea why? <...

I have an issue with the following code. I want to replace a string by another one, and generate an img code. However, I got an error message: str.replace is not a function. Any idea why? <...

  1. javascript replace function arguments
  2. javascript replace function not working
  3. javascript replace function string
  4. javascript replace function body
  5. javascript replace function with regex
  6. javascript replace function implementation
  7. javascript replace function with regular expression
  8. javascript replace function
  9. javascript replace function example
  10. javascript replace function parameter
  11. javascript replace function callback
  12. javascript replace function for special characters
  13. javascript replace function in object
  14. javascript replace function prototype
  15. javascript replace function not working in ie
  16. javascript replace function w3schools
  17. javascript replace function escape characters
  18. javascript replace function return value
  19. javascript replace function multiple
  20. javascript replace function browser compatibility

I have created a html dom structure like this. I have used the ng-click to toggle the visibility of the DOM structure. For example if I am clicking in menu1 and if it is not visible it will be make ...

I have created a html dom structure like this. I have used the ng-click to toggle the visibility of the DOM structure. For example if I am clicking in menu1 and if it is not visible it will be make ...

  1. toggle visibility html
  2. toggle visibility html element javascript
  3. toggle hide html
  4. toggle password visibility html
  5. toggle visibility javascript html
  6. toggle button visibility html
  7. toggle visibility of html element
  8. toggle visibility div html
  9. html toggle visibility without javascript
  10. html toggle visibility on click
  11. html toggle visibility jquery
  12. html toggle visibility checkbox

I am putting together an HTML5 form for music teachers so they can classify their music library a bit easier. One of the requested elements is a double handled range slider that would be able to ...

I am putting together an HTML5 form for music teachers so they can classify their music library a bit easier. One of the requested elements is a double handled range slider that would be able to ...

I have an JS collection (array of objects with few properties). let xyz = [{ categoryId: 1, categoryName: 'Test', programId: 112, programName: 'Program Test', value: 5050, ...

I have an JS collection (array of objects with few properties). let xyz = [{ categoryId: 1, categoryName: 'Test', programId: 112, programName: 'Program Test', value: 5050, ...