Jquery Portlet horizontal scroll problem
Ho开发者_Go百科w can I prevent horizontal scrolling when dragging items using sortable portlets? Currently when you drag an item, you can scroll to the right without any limits as seen in the demo: http://jqueryui.com/demos/sortable/#portlets
EDIT: I just noticed that the same thing happens when you drag the element vertically, it just goes on forever. Any way to add some kind of boundaries to the scrolling?
Thanks.
Use
axis: "y"
//Example
$(function() {
$(setSelector).sortable({
axis: "y",
cursor: "move",
opacity: 0.5,
});
});
I've never used sortable, but I've written code to restrict scrolling to a certain area so maybe you can take a look at this code and figure out what to do.
scroll_position = $(window).scrollTop();
$(window).scroll(function () {
if($(window).scrollTop() < scroll_position) {
// code to cancel sort
}
});
For horizontal scrolling, look at http://api.jquery.com/scrollLeft/
You can use containment
(Link to the API). You can write something like this:
$(selector).sortable({
containment: 'body'
})
This will lock your portlets in the body element. You can also use selectors or other special words to choose what the portlets are locked into. Just make sure that the containment elements have a height when they're displayed.
精彩评论