Home > Web Front-end > JS Tutorial > body text

Angularjs creates a pop-up box to achieve dragging effect_AngularJS

WBOY
Release: 2016-05-16 15:21:27
Original
1075 people have browsed it

The example in this article introduces the relevant code for creating a pop-up box in angularjs to achieve the drag effect. In the project, the pop-up box used in angular-ui-bootstrap needs to be made draggable and shared with everyone for your reference. The specific content As follows

Operation rendering:

Since it is not implemented in the source file, you need to implement the instruction yourself. The following is the instruction. It can be implemented by personal testing.

.directive('draggable', ['$document', function($document) {
        return function(scope, element, attr) {
        var startX = 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.preventDefault();
          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);
        }
        };
  }]);
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone’s study.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!