【问题标题】:jquery touch punch not workingjquery触摸打孔不起作用
【发布时间】:2015-09-16 00:44:26
【问题描述】:

我正在尝试让我的拖放功能在手机上运行。所以我正在尝试使用 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"

【问题讨论】:

    标签: javascript jquery ruby-on-rails jquery-ui-touch-punch


    【解决方案1】:

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

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

    这应该让你启动并运行!

    【讨论】:

    • 谢谢。我把它移给了供应商。所以在我的 application.js 文件中我会添加 //= require jquery.ui.touch-punch.min.js ?另外,如果我添加它,我是否还需要这条线:%script{:src => "/app/assets/javascripts/jquery.ui.touch-punch.min.js"}
    • 利用Rails Asset Pipeline 并要求application.js 中的所有javascript。您将使用//= require jquery.ui.touch-punch.min
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-27
    • 2013-07-06
    • 1970-01-01
    • 2013-02-06
    • 1970-01-01
    • 2014-08-06
    • 1970-01-01
    相关资源
    最近更新 更多