jQuery-Draggable参数介绍

参考网站:http://blog.sina.com.cn/s/blog_48474ade0100exfg.html

相关jquery效果下载:http://www.jquery.com

                                    http://www.jqueryui.com

                                    http://jqueryui.com/draggable/

默认设置值:

$.extend($.ui.draggable, {
version: “1.7.1″,
eventPrefix: “drag”,
defaults: {
addClasses: true,
appendTo: “parent”,
axis: false,
cancel: “:input,option”,
connectToSortable: false,
containment: false,
cursor: “auto”,
cursorAt: false,
delay: 0,
distance: 1,
grid: false,
handle: false,
helper: “original”,
iframeFix: false,
opacity: false,
refreshPositions: false,
revert: false,
revertDuration: 500,
scope: “default”,
scroll: true,
scrollSensitivity: 20,
scrollSpeed: 20,
snap: false,
snapMode: “both”,
snapTolerance: 20,
stack: false,
zIndex: false
}
});

============================================================
Default:
$(”#draggable”).draggable();
============================================================

events:
var $start_counter = $(’#event-start’), $drag_counter = $(’#event-drag’), $stop_counter = $(’#event-stop’);
var counts = [0,0,0];
$(”#draggable”).draggable({
start: function() {
counts[0]++;
updateCounterStatus($start_counter,counts[0]);
},

drag: function() {
counts[1]++;
updateCounterStatus($drag_counter,counts[1]);
},

stop: function() {
counts[2]++;
updateCounterStatus($stop_counter,counts[2]);
}
});
});

function updateCounterStatus($event_counter,new_count) {

// first update the status visually…
if (!$event_counter.hasClass(’ui-state-hover’)) {
$event_counter.addClass(’ui-state-hover’)
.siblings().removeClass(’ui-state-hover’);
}

// …then update the numbers
$(’span.count’,$event_counter).text(new_count);

============================================================

constrain-movement(限制范围移动):
$(”#draggable”).draggable({ axis: ‘y’ });  //限制y轴
$(”#draggable2″).draggable({ axis: ‘x’ }); //限制x轴
$(”#draggable3″).draggable({ containment: ‘#containment-wrapper’, scroll: false }); //不出现滚动条
$(”#draggable4″).draggable({ containment: ‘#demo-frame’ });
$(”#draggable5″).draggable({ containment: ‘parent’ }); //限制在父系框架中

============================================================

delay-start(延时移动):
$(”#draggable”).draggable({ distance: 20 }); //移动20像素开始拖动
$(”#draggable2″).draggable({ delay: 1000 });//延迟1秒后开始拖动
============================================================

snap-to (吸附移动):
$(”#draggable”).draggable({ snap: true }); //默认,任何方式吸附
$(”#draggable2″).draggable({ snap: ‘.ui-widget-header’ }); //以某元素的内外径吸附
$(”#draggable3″).draggable({ snap: ‘.ui-widget-header’, snapMode: ‘outer’ }); //以某元素外径吸附,吸附方式:本上吸其下,本下吸其上. 内径吸附:inner, 吸附方式:相反
$(”#draggable4″).draggable({ grid: [20,20] });//以一定距离移动
$(”#draggable5″).draggable({ grid: [80, 80] });

============================================================

scroll:

$(”#draggable”).draggable({ scroll: true });
$(”#draggable2″).draggable({ scroll: true, scrollSensitivity: 100 });  //滚动条敏感度
$(”#draggable3″).draggable({ scroll: true, scrollSpeed: 100 });  //滚动速度

============================================================

revert position(恢复到原始位置):
$(”#draggable”).draggable({ revert: true });     //revert:true 设置为恢复到位置
$(”#draggable2″).draggable({ revert: true, helper: ‘clone’ });              //helper:’clone’ 复制拖动

============================================================

visualfeedback (视觉效果):
$(”#draggable”).draggable({ helper: ‘original’ });  //设置不复制(初始化设置)
$(”#draggable2″).draggable({ opacity: 0.7, helper: ‘clone’ }); //opacity设置透明度,并克隆元素
$(”#draggable3″).draggable({
cursor: ‘move’, //设置鼠标图形
cursorAt: { top: -12, left: -20 }, //位置定位坐标设置
helper: function(event) {
return $(’<div class=”ui-widget-header”>I\’m a custom helper</div>’);
} //新建提示元素,上面设置其以鼠标定位位置值

});

$(”#set div”).draggable({ stack: { group: ‘#set div’, min: -1 } });//群组设置拖动,并且最后添加的元素叠加到该群组的最上面.适合做许愿板效果。

============================================================

Drag handle (拖动点设置):
$(”#draggable”).draggable({ handle: ‘p’ }); //handle设置实现拖动位置
$(”#draggable2″).draggable({ cancel: “p.ui-widget-header” }); //cancel设置限制拖动位置

============================================================

Cursor style (鼠标样式):
$(”#draggable”).draggable({ cursorAt: { cursor: ‘move’, top: 56, left: 56 } }); //cursor设置鼠标样式, top、left、right、bottom设置元素相对鼠标的定位点
$(”#draggable2″).draggable({ cursorAt: { cursor: ‘crosshair’, top: -5, left: -5 } });
$(”#draggable3″).draggable({ cursorAt: { bottom: 0 } });
===========================================================

Cursor style (鼠标样式):
$(”#draggable”).draggable({ cursorAt: { cursor: ‘move’, top: 56, left: 56 } }); //cursor设置鼠标样式, top、left、right、bottom设置元素相对鼠标的定位点
============================================================

Draggable+sortable:
$(”#sortable”).sortable({
revert: true
});

$(”#draggable”).draggable({
connectToSortable: ‘#sortable’, //设置拖动加入到其他列表中
helper: ‘clone’,
revert: ‘invalid’
});


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值