English 中文(简体)
j 固定限额
原标题:jQuery UI draggable limitation

I m 采用j Query UI 计分模块,我想做一件简单的事,但我无法找到任何帮助,利用谷歌(也许我找错)。 这是我的法典:

 $("#table").draggable({
     axis: "x",
     drag: function() {
         if(parseInt($(this).css("left")) <= 0)
         {
             return false;
         }   
     }   
 }); 

As you could except I want to prevent dragable element of reaching CSS left value lower than 0. But this code doesn t work - if I drag element beyond CSS left 0 it blocks. Could you help me?

<><>UPDATE:

@VisioN感谢您的帮助。 现在,一切都像我所希望的那样发挥作用。 这里是我的最后法典。 或许可以帮助儿子:

var table_dim = [1898, 1024];
width = Math.round((table_dim[0]/table_dim[1])*$(window).height());
height = $(window).height();
$(document.createElement("img"))
    .attr("src", "images/table.png")
    .attr("height", height)
    .attr("width", width)
    .attr("id", "table")
    .css(
        {"display": "block",
         "position": "absolute",
         "left" : -((width-$(window).width())/2)+"px",
         "z-index": "-9999"
    })  
    .appendTo("body");


$("#table").draggable({
    axis: "x",
    drag: function(event, ui) {
        if (ui.offset.left < $(window).width()-width) {
            $(this).data( draggable ).position.left = $(window).width()-width;
        } else if(ui.offset.left > 0)
        {   
            $(this).data( draggable ).position.left = 0;
        }   
    }   
}); 
问题回答

如何使用

$("#table").draggable({
    axis: "x",
    containment: "document"
});​

As containment value you can use parent , document , window or [x1, y1, x2, y2].

DEMO: http://jsfiddle.net/bAffp/

<>UPDATE>。 另一种选择是纠正内部价值,同时拖累。

$("#table").draggable({
    axis: "x",
    drag: function(event, ui) {
        if (ui.offset.left < 0) {
            $(this).data( draggable ).position.left = 0;
        }
    }
});​

http://jsfiddle.net/bAffp/3/“rel=“nofollow” http://jsfiddle.net/bAffp/3/。

Try this code

(美元)

限额:{:50,左边:100,底层:200,右边:200}

iii

联系

rel=“nofollow> http://jsfiddle.net/bAffp/2/。





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签