当我们向下滚动时,jquery resizable在滚动div容器内不起作用

时间:2012-08-21 15:03:49

标签: jquery scroll resizable

如果我将调整大小移到#holder宽度附近,那么调整大小可以比#holder宽度宽。这意味着收容限制现在不起作用! 我怎么能让它正常工作????非常感谢! 前提条件:我必须保持容器的样式.overflow:auto; position:relative ...等。 他们必须保留出于某种原因。

下面是代码:

 <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>jQuery UI Resizable - Constrain resize area</title>
    <link rel="stylesheet" href="http://jqueryui.com//themes/base/jquery.ui.all.css">
    <script src="http://jqueryui.com//jquery-1.8.0.js"></script>
    <script src="http://jqueryui.com//ui/jquery.ui.core.js"></script>
    <script src="http://jqueryui.com//ui/jquery.ui.widget.js"></script>
    <script src="http://jqueryui.com//ui/jquery.ui.mouse.js"></script>
    <script src="http://jqueryui.com//ui/jquery.ui.resizable.js"></script>
     <script src="http://jqueryui.com//ui/jquery.ui.draggable.js"></script>
    <link rel="stylesheet" href="../demos.css">
    <style>
    #container { width: 500px; height: 500px;overflow:auto;position:relative }
    #container h3 { text-align: center; margin: 0; margin-bottom: 10px; }
    #resizable {   width: 150px; height: 150px;left:80px;top:50px;background-color:red;border:2px }
    #resizable, #container { padding: 0.5em; }
    #gap { width: 1000px; height: 1000px; position:absolute;left:0;top:0;  }
    #holder { width: 800px; height: 800px; position:absolute;left:0;top:0;  }
    </style>
    <script>
    $(function() {
        $( "#resizable" ).resizable({
            containment: "#holder"
        });
         $( "#resizable" ).draggable({
            containment: "#holder"
        });

    });
    </script>
</head>
<body>

<div class="demo">
<textarea cols=120 rows=10>dddddddddddddddddddddddd</textarea>
<input type=text value="ddddddddddddddddddddddddd"/>
<div style="width:500px;height:600px">
<div id="container" class="ui-widget-content">
    <h3 class="ui-widget-header">Containment</h3>

    <div id="gap" class="ui-widget-content">
 <div id="holder" class="ui-widget-content">
    </div>
    <div id="resizable"  >
        <h3 class="ui-widget-header">Resizable</h3>
    </div>
    </div>
</div>
</div> 
</div><!-- End demo -->



<div class="demo-description">
<p>Define the boundaries of the resizable area. Use the <code>containment</code> option to specify a parent DOM element or a jQuery selector, like 'document.'</p>
</div><!-- End demo-description -->

</body>
</html>

1 个答案:

答案 0 :(得分:0)

您需要一个主题才能运行此代码。

在我的电脑中,我刚刚改变了

<link rel="stylesheet" href="../demos.css">

<link rel="stylesheet" href="~/Content/ui-lightness_1.8.24/jquery-ui-1.8.24.custom.css" />

它摇滚。例如,下载主题ui-lightness_1.8.24,用它更改你的demo css然后再试一次。