我正在尝试让我的拖放功能在手机上运行。所以我尝试使用 jquery touchpunch,但它似乎无法在手机上启用拖放。
这是我的代码。我将 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"
最佳答案
以下是我为使 Touch Punch 正常工作而采取的步骤:
- 首先让您的网站在桌面上完全按照您希望的方式运行。 Touch Punch 本身不执行任何操作,它只是扩展 jQuery UI。
- 下载 Touch Punch javascript 并将其包含在您的 Rails 应用程序中。
/app/assets/javascripts/
就可以,但我更喜欢将第三方 javascript 放在/vendor/assets/javascripts/
中。 - 将该文件包含在您的
application.js
文件中,在所有 jquery 和 jquery-ui 需要之后。
这应该能让你启动并运行!
关于javascript - jquery触摸打洞不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32597933/