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;
}
}
});