我正在尝试创建具有开/关状态的开关按钮(使用 Twitter Bootstrap )。
在这个演示中你可以看到我有按钮的外边框。按钮可拖动适用于 x-Offset。
我希望按钮不要超出我的边界。所以我将它放在 div
元素中并将其设置为某个宽度。
我不认为它进展顺利。
请建议我如何将此按钮绑定(bind)到边框区域。
fiddle 链接- http://jsfiddle.net/stackmanoz/w6AsC/3/
一些代码架子-
<div style="width:200px;border:1px dashed #ddd">
<p id="button" class="btn-inverse btn">Regular link</p>
</div>
和脚本-
$(document).ready(function () {
$('#button').draggable({ axis: 'x' });
});
最佳答案
添加额外参数,如 Docs, your friend and helper 中所述.
$('#button').draggable({ axis: 'x',containment: "parent" });
这样理论上你甚至不需要轴参数。
关于javascript - 包含在 jquery 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14975136/