Andrew
Andrew

Reputation: 11

Jquery Portlet horizontal scroll problem

How 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.

Upvotes: 1

Views: 1918

Answers (3)

PrinceTyke
PrinceTyke

Reputation: 213

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.

Upvotes: 0

soiswis
soiswis

Reputation: 21

Use

axis: "y"

//Example
$(function() {
    $(setSelector).sortable({
        axis: "y",
        cursor: "move",
        opacity: 0.5,
    });
});

Upvotes: 2

pulsedemon
pulsedemon

Reputation: 431

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/

Upvotes: 0

Related Questions