“链接”到可拖动调用以启用触摸功能

发布于 2024-11-15 13:33:50 字数 2342 浏览 2 评论 0原文

我对 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寄意 2024-11-22 13:33:50

好吧,链接是这样工作的,假设您有以下代码:

$('#someDiv').show();
$('#someDiv').addClass('someClass');
$('#someDiv').removeClass('someOtherClass');

相反,您可以像这样链接这些调用:

$('#someDiv').show().addClass('someClass').removeClass('someOtherClass');

这是有效的,因为 jQuery 函数随后返回该元素,因此您可以在同一元素或结果元素上“链接”函数调用。

在你的情况下,我相信它应该在 $.widget 调用结束后被链接:

$.widget(...).touch({
    animate: false,
    sticky: false,
    dragx: true,
    dragy: true,
    rotate: false,
    resort: true,
    scale: false
});

或者可以用其他方式完成:

$('#yourElement').draggable(...).touch(...);

Well, chaining works like this, imagine you have the following code:

$('#someDiv').show();
$('#someDiv').addClass('someClass');
$('#someDiv').removeClass('someOtherClass');

Instead you can chain these calls like such:

$('#someDiv').show().addClass('someClass').removeClass('someOtherClass');

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:

$.widget(...).touch({
    animate: false,
    sticky: false,
    dragx: true,
    dragy: true,
    rotate: false,
    resort: true,
    scale: false
});

Or the other way it can be done:

$('#yourElement').draggable(...).touch(...);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文