我想在可移动div内制作一个像窗口一样的div

时间:2018-08-08 06:21:18

标签: javascript jquery html css

我想在可移动div的内部制作一个div,它的作用就像一个可以容纳内容并带有与可拖动div相同宽度的窗口。就像计算机上的程序一样工作/看起来像(顶部的栏是可拖动的,但是如果您尝试在应用程序中拖动内容,则将不起作用)。

到目前为止,这是我的代码:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
    <style>
        html, body {
            height: 100%;
            margin: 0;
        }

        #divcontainer {
            border: 1px solid lightgray;
            width: 100%
            height: 100%

        }

        #makeitmove {
            background: lightgray;
            resize: both;
            overflow: auto;
            text-align: center;
            width: 500px;
            height: 76px;
            border: 1px solid grey;
            cursor: move;
        }
    </style>
    <script>
        $(document).ready(function () {
            $("#makeitmove").draggable({containment: "#divcontainer", scroll: false});
        });
    </script>
    <div id="window" style="display: none;"></div>
</head>
<body>
    <div id="divcontainer" style="height: 100vh;">
        <div id="makeitmove">Calculator
        </div>
    </div>
</body>
</html>

如果您也为我禁用了主页上的滚动条(但没有为窗口禁用),还不确定如何做到吗?提前非常感谢您的帮助!

2 个答案:

答案 0 :(得分:2)

您需要使用draggable的handle选项来指定要启用拖动的位置。

有关更多信息,https://jqueryui.com/draggable/#handle

 <div ng-controller="psHeaderCtrl">
  <ul class="nav navbar-toolbar navbar-right navbar-toolbar-right">
   <li class="nav-item" id="plus">
     <a class="nav-link" data-toggle="" href="javascript:void(0)" 
       title="plus" ng-click="addAlertPin()">
       <i class="icon wb-plus" aria-hidden="true"></i>
     </a>
   </li>
  </ul>
</div>

答案 1 :(得分:0)

已编辑...

你去了!

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script language="javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>
<style>
html, body{
height:100%;
margin:0;
}

#divcontainer{
border: 1px solid lightgray;
box-sizing: border-box;
}
#makeitmove{
background: white;
resize: both;
overflow: auto;
text-align: center;
width: 500px;
height: 76px;
border: 1px solid grey;
}
#handle {
background: lightgray;
height: 20px;
cursor: move;
}
</style>
<script>
$(document).ready(function(){
$("#makeitmove").draggable( {containment: "#divcontainer", handle: "#handle", scroll: false} );
});
</script>
<div id="window" style="display: none;"></div>
</head>
<body>
<div id="divcontainer" style="height: 100vh;">
<div id="makeitmove">
    <div id="handle"></div>
    <span>Calculator</span>
</div>

</div>
</body>
</html>