0

我试图让我的拖放功能在手机上工作。所以我正在尝试使用 jquery touch punch,但它似乎并没有在手机上启用拖放功能。

这是我的代码。我将 jquery.ui.touch-punch.min.js 放在 /app/assets/javascripts/ 文件夹中。

=render :layout => 'shared/form_layout' do
  .row-fluid
    .col-xs-12.text-center#new-image
      %h1 Edit Collection
    = form_for @collection, :html => { :method => :put, :multipart => true } do |f|
      .row-fluid
        %label{for: "image"} Drag to Reorder:
        %script{:src => "http://code.jquery.com/jquery-1.7.2.min.js"}
        %script{:src => "http://code.jquery.com/ui/1.8.21/jquery-ui.min.js"}
        %script{:src => "/app/assets/javascripts/jquery.ui.touch-punch.min.js"}
        %ul.list-inline.form-group.edit-grid.clearfix#collectiondrag{"data-update-url" => sort_collections_url}
          - @images.each do |image|
            %li{class: "image", id: "image_#{image.id}"}
                .edit-item{:style => "background-image: url(#{image.photo.url})"}
        %hr.m-y-20
        .text-center
          = f.submit "Save Changes", class: "button btn btn-primary w-100", id: "sort_collection"
4

1 回答 1

2

以下是我为让 Touch Punch 工作而采取的步骤:

  • 首先让您的网站在桌面上完全按照您的要求运行。Touch Punch 本身什么也不做,它只是扩展了 jQuery UI。
  • 下载 Touch Punch javascript 并将其包含在您的 Rails 应用程序中。/app/assets/javascripts/可以,但我更喜欢将第三方 javascripts 放入/vendor/assets/javascripts/.
  • 在您的所有 jquery 和 jquery-ui 需要之后,将文件包含在您的application.js文件中。

这应该让你启动并运行!

于 2015-09-16T01:09:41.697 回答