jQuery可拖动选项 [英] jquery draggable options

查看:96
本文介绍了jQuery可拖动选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击按钮时,我希望可拖动对象恢复到其原始位置. 我使用了破坏"选项,但它似乎不起作用.它会禁用拖动功能,但不会恢复到原始位置.

i want the draggable object to revert back to its original position when i click a button. i used 'destroy' option but it doesnt seem to work. it disables the dragging but doesnt revert back to original position.

有人可以帮忙吗?

编辑部分:

$('#Zoom').toggle(function() {
                $("#draggable").draggable({});},
            function() {
                $("#draggable").draggable('destroy');});

这是一个切换按钮,我正在使用它来启用拖动. destroy选项仅禁用拖动,并且不将对象恢复到原始位置.

this is a toggle button that i am using to enable dragging. the destroy option only disables dragging and does not revert the object back to the original position.

这也是我要使对象返回其原始位置的按钮:

nextImg.addEventListener('click', function() {img.setAttribute("src", "img"+(++imgnum)+".jpg");}, false);

推荐答案

如何?

<script type="text/javascript">
jQuery(document).ready(function() { 
    $("#draggable").data("Left", $("#draggable").position().left)
                    .data("Top", $("#draggable").position().top);
    $("#draggable").draggable();

    $("#nextImg").bind('click', function() {
        $("#draggable").animate(
            { "left": $("#draggable").data("Left"), 
                "top": $("#draggable").data("Top")
            }, "slow");
        $("#draggable").attr("src", "img"+(++imgnum)+".jpg");
    });
});
</script>

我做了一些假设,例如id为"nextImg"的nextImg对象,以便我可以使用jQuery绑定click事件(在javascript事件绑定过程中又少一步了?),我还假设您真的不想破坏拖动功能.

I've made some assumptions, such as the nextImg object having an id of "nextImg" so that I can bind the click event using jQuery (one less step in the javascript event binding process?) I'm also assuming that you don't really want to destroy the drag functionality.

这篇关于jQuery可拖动选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆