2015-05-14 131 views
0

我想實現拖放在一個固定的高度和寬度的容器,但滾動的模仿無限表面的需求。jquery ui可拖動滾動自動

這裏是CSS

.drag { 
    width: 100px; 
    height: 100px; 
    border: 1px solid black; 
    cursor: pointer; 
    border-radius: 10px; 
    text-algin: center; 
    background-color: lightpink; 
} 

下面是HTML。 Box是具有固定寬度和高度的容器,但具有自動溢出功能。

<div id="box" style="width:500px;height:300px;border:1px solid black;background-color:lightgreen;overflow:auto;"> 
    <div id="dragx" class="drag"><p>Drag me</p></div> 
</div> 

這是javascript。

$(function() { 
    $("div[id='dragx']").draggable({ 
     containment: "#box", 
     scroll: true 
    }); 
}); 

完全跑步例如可以在http://jsbin.com/tafof/2/edit?html,output

基本上可以發現,當我拖動DIV極端向下或極右我想滾動條顯示出來,並讓我儘量拖。但目前它不允許我在固定的寬度和高度之外拖動。

當我拖到極點時,我需要什麼使滾動條可以按需顯示?

回答

-1

你需要你的#box有溢出:scroll屬性而不是auto。

+0

我只想在畫布較大的情況下顯示滾動條,以免滾動。 – prabir

+0

@prabir所以使用JavaScript來改變溢出屬性取決於你的元素x和y的位置 – onedayiwillchangethis