jQuery draggable div使溢出:隐藏页面滚动

时间:2010-07-20 14:48:40

标签: jquery jquery-ui scroll draggable

我使用jQuery网站上的.draggable()UI设置了一个可拖动的div。我的主容器div被设置为窗口的宽度和高度溢出:隐藏所以页面上永远不会有滚动条。我的问题是,当我开始将可拖动的div拖离页面时,它会使我的页面滚动(我不想要)。这是我的代码:

 html, body{
   margin:0 auto;
   overflow:hidden;
   }

 #container #date-box{
position:absolute;
cursor:pointer;
background:url(/img/EWI/login/date-box.png) no-repeat;
width:247px;
height:21px;
z-index:9999;
margin:40px 0 0 15px;
}

  $("div#container div#date-box").draggable();

请帮助!!!!

2 个答案:

答案 0 :(得分:7)

http://jqueryui.com/demos/draggable/#option-scroll

默认值设置为滚动容器。在.draggable中设置选项({“scroll”:false});

答案 1 :(得分:1)

你需要包含你的可拖动div:)

$("div#container div#date-box").draggable({ containment: '#containmentDivId', scroll: false });