ANGULARJS Create a pop-up box to implement the drag effect _angularjs

Source: Internet
Author: User

This article introduces the Angularjs create pop-up box to achieve the drag effect of the relevant code, the project needs to be used in the Angular-ui-bootstrap pop-up box, so that it can be dragged, shared for everyone to reference, the specific content as follows

Run Effect chart:

Because the source file is not implemented, you need to implement the instructions, the following is the directive, the test can be achieved.

. directive (' draggable ', [' $document ', function ($document) {return function (scope, element, attr) {var s
        Tartx = 0, Starty = 0, x = 0, y = 0; 
        Element= angular.element (Document.getelementsbyclassname ("Modal-dialog"));

        Element.css ({position: ' relative ', cursor: ' move '}); Element.on (' MouseDown ', function (event) {//Prevent default dragging of selected content Event.preven
          Tdefault ();
          StartX = Event.pagex-x;
          Starty = event.pagey-y;
          $document. On (' MouseMove ', MouseMove);
        $document. On (' MouseUp ', MouseUp);

        });
          function MouseMove (event) {y = Event.pagey-starty;
          x = Event.pagex-startx;
        Element.css ({top:y + ' px ', left:x + ' px '});
          function MouseUp () {$document. Off (' MouseMove ', MouseMove);
        $document. Off (' MouseUp ', MouseUp);
      }  };
 }]);

The above is the entire content of this article, I hope to help you learn.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.