“链接”到可拖动调用以启用触摸功能
我对 jquery ui 很陌生,但由于我的项目的性质,我已经陷入了困境!基本上,我需要帮助的是,我有一个文件,该文件将某些自定义设置应用于 jquery ui 可拖动小部件,并且我想进一步自定义以启用触摸功能,以便该小部件在移动触摸屏设备上运行。也就是说,我的代码看起来像这样:
/*
* jQuery UI Draggable
*
* Depends:
* jquery.ui.core.js
* jquery.ui.mouse.js
* jquery.ui.widget.js
*/
(function( $, undefined ) {
$.widget("ui.draggable", $.ui.mouse, {
widgetEventPrefix: "drag",
options: {
addClasses: true,
appendTo: "parent",
axis: false,
connectToSortable: false,
containment: false,
cursor: "auto",
cursorAt: false,
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
},
_create: function() {
if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
this.element[0].style.position = 'relative';
(this.options.addClasses && this.element.addClass("ui-draggable"));
(this.options.disabled && this.element.addClass("ui-draggable-disabled"));
this._mouseInit();
},
destroy: function() {
if(!this.element.data('draggable')) return;
this.element
.removeData("draggable")
.unbind(".draggable")
.removeClass("ui-draggable"
+ " ui-draggable-dragging"
+ " ui-draggable-disabled");
this._mouseDestroy();
return this;
},
...等等。
我看过这篇文章:如何我可以为触摸屏制作一个可拖动的 jQuery UI 'draggable()' div 吗?,它看起来像是我想要做的事情的理想解决方案,但我不确定“链接这个”是什么意思到我的 jQuery UI Draggable() 调用“. block: 应该
.touch({
animate: false,
sticky: false,
dragx: true,
dragy: true,
rotate: false,
resort: true,
scale: false
});
放在我的代码中的哪里?这可能是一个愚蠢的问题,抱歉。我是初学者! :) 谢谢!!
I'm very new to jquery ui but due to the nature of my project I've sort of been thrown right into the deep end! Basically what I need help with is that I have a file that applies certain customizations to the jquery ui draggable widget, and I want to further customize to enable touch capability so that the widget is functional on mobile touch screen devices. That is, my code looks something like this:
/*
* jQuery UI Draggable
*
* Depends:
* jquery.ui.core.js
* jquery.ui.mouse.js
* jquery.ui.widget.js
*/
(function( $, undefined ) {
$.widget("ui.draggable", $.ui.mouse, {
widgetEventPrefix: "drag",
options: {
addClasses: true,
appendTo: "parent",
axis: false,
connectToSortable: false,
containment: false,
cursor: "auto",
cursorAt: false,
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
},
_create: function() {
if (this.options.helper == 'original' && !(/^(?:r|a|f)/).test(this.element.css("position")))
this.element[0].style.position = 'relative';
(this.options.addClasses && this.element.addClass("ui-draggable"));
(this.options.disabled && this.element.addClass("ui-draggable-disabled"));
this._mouseInit();
},
destroy: function() {
if(!this.element.data('draggable')) return;
this.element
.removeData("draggable")
.unbind(".draggable")
.removeClass("ui-draggable"
+ " ui-draggable-dragging"
+ " ui-draggable-disabled");
this._mouseDestroy();
return this;
},
...etc.
I've seen this post: How can I make a jQuery UI 'draggable()' div draggable for touchscreen?, and it looks like an ideal solution for what I'm trying to do, but I'm not sure what is meant by " chain this onto my jQuery UI draggable() call ". Where in my code should the block:
.touch({
animate: false,
sticky: false,
dragx: true,
dragy: true,
rotate: false,
resort: true,
scale: false
});
go? This may be a stupid question, sorry. I'm a beginner! :) Thanks!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,链接是这样工作的,假设您有以下代码:
相反,您可以像这样链接这些调用:
这是有效的,因为 jQuery 函数随后返回该元素,因此您可以在同一元素或结果元素上“链接”函数调用。
在你的情况下,我相信它应该在 $.widget 调用结束后被链接:
或者可以用其他方式完成:
Well, chaining works like this, imagine you have the following code:
Instead you can chain these calls like such:
This works because jQuery functions return the element afterwards, hence you can "chain" function calls on the same element, or a resulting element.
And in your case, I believe it should be chained after the end of the call to $.widget:
Or the other way it can be done: