admin管理员组文章数量:1178552
I have a draggable defined this way:
$("#drag_area a").live("mouseup", function() {
var object = $(this);
var class_array = $(this).attr("class").split(" ");
element(object,class_array);
return false;
}).draggable({
containment: "#drag_area",
grid: [44, 44],
zIndex: 1000
}).each(function(i, item){
});
When i drag an item of the type 'drag_area a', if i scroll the page while dragging it, the item exits from containment... It is not a desidered situation, so how can i avoid this? Can i disable page scrolling during dragging?
I have a draggable defined this way:
$("#drag_area a").live("mouseup", function() {
var object = $(this);
var class_array = $(this).attr("class").split(" ");
element(object,class_array);
return false;
}).draggable({
containment: "#drag_area",
grid: [44, 44],
zIndex: 1000
}).each(function(i, item){
});
When i drag an item of the type 'drag_area a', if i scroll the page while dragging it, the item exits from containment... It is not a desidered situation, so how can i avoid this? Can i disable page scrolling during dragging?
Share Improve this question asked Sep 4, 2015 at 10:34 Sasha GrievusSasha Grievus 2,6866 gold badges33 silver badges61 bronze badges 4 |3 Answers
Reset to default 35I solved that problem with one line of css on dragging element touch-action: none;
You'll be using all your draggable elements without any container, i.e. why when you Drag-n-Drop your elements the whole page scrolls due to dragging.
Instead of that do as:
<div class="dragWrapper">
<!-- Place all your draggable elements here -->
</div>
set a max-height
and overflow
of the dragWrapper
class as:
.dragWrapper {
max-height: 400px;
overflow: auto;
}
Now when you Drag-n-Drop your elements, instead of your body, scroll will be inside the container only.
Hope that will do the trick for you(which already did ;).
Take a look at this jsfiddle.
I've made it based on this SO question: How to disable scrolling temporarily?
Here is an excerpt:
function disableScroll() {
if (window.addEventListener) // older FF
window.addEventListener('DOMMouseScroll', preventDefault, false);
window.onwheel = preventDefault; // modern standard
window.onmousewheel = document.onmousewheel = preventDefault; // older browsers, IE
window.ontouchmove = preventDefault; // mobile
document.onkeydown = preventDefaultForScrollKeys;
}
$("#draggable").draggable({
start: function () {
disableScroll();
}
});
本文标签: javascriptHow to disable page scroll while dragging draggable in jqueryStack Overflow
版权声明:本文标题:javascript - How to disable page scroll while dragging draggable in jquery? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738002726a2047525.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
overflow: auto
so when you drag-drop, scroll will be remain in the container itself. – vivekkupadhyay Commented Sep 4, 2015 at 10:37