简体   繁体   English

带有触摸的可拖放,可拖放和移动幻灯片

[英]Draggable, Droppable and Mobile Slide with Touch

The Problem: 问题:

My problem is that I've had this functioning until adding just a small bits of code to make it only load on screen size lower then 480, so mobile. 我的问题是,直到添加少量代码以使其仅在小于480的屏幕尺寸上加载(如此移动),我才具有这种功能。 Before, it worked perfectly fine, now, no matter how much I go and retrace my steps of what I've done, I just can not figure it out and hope someone out there will answer me why this isn't happening. 以前,它工作得非常好,现在,无论我走了多少,然后回溯我所做的工作,我都无法弄清楚,希望在那里的人能够回答我为什么不发生这种情况。

What's Working 在做什么

So I have more then one thing happening here in my project, I have things being dragged, things being saved, you can swipe with your finger from left to right and drag an icon and drop it on the items you swipe. 因此,在我的项目中,发生了一件事情,我正在拖动东西,保存了东西,您可以用手指从左向右滑动,然后将一个图标拖放到您滑动的项目上。

What works right now is the; 现在有效的是; swipe, the drag but dropping my icon on the swipe items, just don't get saved or accepted. 滑动,将我的图标拖放到滑动项上,只是不会被保存或接受。 It worked before and not now. 它以前而不是现在起作用。 I'm starting to thing it might be just the wrong javascript version of something. 我开始觉得事情可能只是某些东西的错误javascript版本。

Here's what I've got 这就是我所拥有的

application.html.erb file

 <%= stylesheet_link_tag "bootstrap" %>
 <%= stylesheet_link_tag "boilerplate" %>
 <%= stylesheet_link_tag "application" %>

 <%= javascript_include_tag "application" %>
 <%= javascript_include_tag "bootstrap" %>
 <%= javascript_include_tag "jquery.ui.touch-punch" %>

 <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.js">         </script>

 <script type="text/javascript">
 function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
 var fileref=document.createElement('script')
 fileref.setAttribute("type","text/javascript")
 fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
 var fileref=document.createElement("link")
 fileref.setAttribute("rel", "stylesheet")
 fileref.setAttribute("type", "text/css")
 fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
 document.getElementsByTagName("head")[0].appendChild(fileref)
 }

 $(function () {
  var width = $(window).width();
  if (width <= 480) {
      loadjscssfile("/assets/idangerous", "js");
      loadjscssfile("/assets/idangerous.swiper", "css");
  } else {
      $('').appendTo('head');
  }
 });
 </script>


 <script type="text/javascript">
 window.onload = function() {
 var mySwiper = new Swiper('.swiper-container',{
  //Your options here:
  mode:'horizontal',
  loop: true
  //etc..
 });  
 }
 </script>

NOTE: That's how my application.html.erb file looks with the javascript I'm loading. 注意:这就是我的application.html.erb文件与正在加载的javascript的外观。

I'm not getting any error but unless I take out iDangerous Swiper scripts, my drag and drop stops working. 我没有收到任何错误,但除非删除iDangerous Swiper脚本,否则我的拖放操作将停止。

What has worked for me is define a helper like so for each needed scenarios. 对我有用的是为每个所需的场景定义一个助手。

def mobile_device?
  request.user_agent =~ /android|blackberry|iphone|ipad|ipod|iemobile|mobile|webos/i
end
helper_method :mobile_device?

def cell_device?
  request.user_agent =~ /android|iphone/i
end
helper_method :cell_device?

Then in my view having the helper methods, I did that for whatever styles and javascripts I needed based on if its a cell or tablet. 然后,在我看来,拥有帮助器方法的我会根据需要的样式和javascript(无论是单元格还是平板电脑)来执行此操作。 Maybe not the cleanest right now but a good work around that in our situation works perfectly from trying it out in live environment. 也许现在不是最干净的方法,但是在实际情况下进行良好的工作可以在实际环境中进行尝试而达到最佳效果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM