Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong position of elements being dragged within a modal #89

Open
drinkbird opened this issue Apr 4, 2016 · 8 comments
Open

Wrong position of elements being dragged within a modal #89

drinkbird opened this issue Apr 4, 2016 · 8 comments

Comments

@drinkbird
Copy link

I've tried using angular-sortable-view within a bootstrap modal window, but when an element is being dragged, it jumps to the right side of the screen.

I presume that happens because the modal is absolutely positioned, but the directive doesn't consider that while calculating the value for 'left' positioning.

@jegorami
Copy link

jegorami commented Apr 5, 2016

Same issue here.

@JSOdin
Copy link

JSOdin commented Jun 12, 2016

having the same issue

@gehrmanng
Copy link

Have you tried to use sv-element="{containment:'.myModalWindow'}"? I had the same behavior that my dragged element jumped somewhere else and above code helped me.

@StefanoVollono
Copy link

same issue

@drinkbird
Copy link
Author

Thanks @GehrmanG I will give it a try

@StefanoVollono
Copy link

  1. I add:
    sv-element="{containment:'.myModalWindow'}"

  2. In my css, I change the vertical align of modal from "transform" to negative margin
    .myModalWindow {
    height: 666px;
    min-height: 0;
    position: absolute;
    right: 0;
    top: 50%;
    // transform: translate(0, -50%); // NOT GOOD FOR DRAG
    margin-top: -333px; // THIS SOLVE FOR ME
    }

i hope help you

@TheLostBrain
Copy link

TheLostBrain commented Nov 4, 2016

If you're using bootstrap / ui-bootstrap (angular) modals and looking for a simple one-liner fix here it is:

.modal-dialog {
transform: none !important;
}

Note: This override is obviously far reaching so just modify as you see fit.

The caveat here is that modals no longer slide down but just fade in (which I actually like better).

Now that the dragged elements are being positioned properly you can constrain them to a particular area using the following line on the draggable item's dom element as mentioned by others above:

sv-element="{containment:'.some-class-that-is-on-the-constraining-parent-dom-element'}"

Credit and thanks to the previous posters because I was pulling my hair out (and there's not much left) trying to figure out what the heck was causing the incorrect positioning in the first place!

@mbryk
Copy link

mbryk commented Feb 1, 2018

^ I didn't originally see this answer, which works great, so I wrote a directive to make the dragged item account for the modal position.

app.directive('svFix', ['$window', '$timeout', function($window, $timeout){
  return {
    restrict: 'A',
    link: function(scope, el) {
      angular.element($window).on('resize', resize);
      var styleEl = $('<style>').appendTo('head');
      $timeout(setTransform, 1000); // Waits for the modal to finish it's animation, so that the position values are correct..

      scope.$on('$destroy', function() {
        angular.element($window).off('resize', resize);
        styleEl.remove();
      });

      function setTransform() {
        var rect = el[0].getBoundingClientRect();
        var propStr = 'transform: translate(-' + rect.left + 'px, -' + rect.top + 'px);';
        styleEl.html('.sv-helper{' + 
          '-webkit-' + propStr
          '-ms-' + propStr
          propStr +
        '}', 0);
      }
      function resize() {
        if(styleEl) setTransform();
      }      
    }
  };
}]);

Just add sv-fix attribute to the outer-most element in the modal-body!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants