zoukankan      html  css  js  c++  java
  • angular-ui-bootstrap 可拖拽模态框

    实现不管是重叠模态框还是单独模态框都可以单独拖拽指令:

    方法一:(弊端:在模态框中的input获取不到焦点)

     1 angular.module('app')
     2 .directive('draggable', function($document){
     3   return function(scope, element, attr) {
     4     var startX = 0, startY = 0, x = 0, y = 0;
     5     element= element.parent().parent(); 
     6     element.css({
     7         position: 'relative',
     8         cursor: 'move'
     9     });
    10 
    11     element.on('mousedown', function(event) {
    12         event.preventDefault();
    13         startX = event.pageX - x;
    14         startY = event.pageY - y;
    15         $document.on('mousemove', mousemove);
    16         $document.on('mouseup', mouseup);
    17     });
    18 
    19     function mousemove(event) {
    20         y = event.pageY - startY;
    21         x = event.pageX - startX;
    22         element.css({
    23         top: y + 'px',
    24         left:  x + 'px'
    25         });
    26     }
    27 
    28     function mouseup() {
    29         $document.off('mousemove', mousemove);
    30         $document.off('mouseup', mouseup);
    31     }
    32     }; 
    33   });
    View Code

    添加指令到页面:

     1 <div draggable class="modal-header border-bottom">
     2     <button type="button" class="close" ng-click="ok()">&times;</button>
     3     <h4 class="modal-title"> Detail</h4>
     4 </div>
     5 <div class="modal-body relative">
     6 
     7 </div>
     8 <div class="modal-footer">
     9     <button type="submit" class="btn btn-primary">Save</button>
    10     <button type="submit" class="btn btn-default">Cancel</button>
    11 </div>
    View Code

     方法二:(推荐使用,适应任何场景)html同方法一

    需要添加的js:

    <script src="https://files.cnblogs.com/files/bertha-zm/jquery-ui.min.js"></script>

    指令如下:

     1 angular.module('app')
     2 .directive('draggable', function($document){
     3   return function(scope, element, attr) {
     4     var startX = 0, startY = 0, x = 0, y = 0;
     5     element= element.parent().parent(); 
     6     element.css({
     7         position: 'relative',
     8         cursor: 'move'
     9     });
    10     element.draggable();
    11   }; 
    12 });
    View Code
  • 相关阅读:
    Spring Bean的生命周期
    使用docker安装虚拟机并打开ssh连接
    查看/设置JVM使用的垃圾收集器
    使用Apollo动态修改线上数据源
    java8之lambda表达式
    Java8之Stream
    @Bean 的用法
    Java中的Filter过滤器
    详解tomcat的连接数与线程池
    什么是ClassLoader
  • 原文地址:https://www.cnblogs.com/bertha-zm/p/8946196.html
Copyright © 2011-2022 走看看