Ruby on Rails || Jquery和JavaScript库不起作用

前端之家收集整理的这篇文章主要介绍了Ruby on Rails || Jquery和JavaScript库不起作用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在Codepen上创建了一个页面,稍后将其添加到我的 Ruby on Rails应用程序( https://codepen.io/salman15/pen/evQVLV)中,其中所有代码都可以正常工作.

创建页面后,我尝试将页面添加到我的Ruby on Rails应用程序中,使用spree(在Cloud 9 https://consulegem-salman15.c9users.io/上运行“服务器在您阅读此内容时可能不会脱机”).我是用以下方式完成的:

第1步:将HTML代码添加到index.html.erb

第2步:将CSS CDN添加到_head.html.erb

第3步:下载所有JavaScript库并将其添加到以下文件夹路径中 – > app – >资产 – > javascripts – >前端 – >商店

第4步:将以下代码添加到我的all.js文件中(在frontend文件夹中)

  1. //= require_tree

此时我的代码应该已经运行,但事实并非如此.

  1. Uncaught TypeError: $(...).easeScroll is not a function
  2. at script.self-a9cf77dbbd3e521fbb44b192f7d525c508a4a35eee8e827785ebb4ce329092f5.js?body=1:341
  3.  
  4. Uncaught TypeError: $(...).logosDistort is not a function
  5. at HTMLDocument.<anonymous> (script.self-a9cf77dbbd3e521fbb44b192f7d525c508a4a35eee8e827785ebb4ce329092f5.js?body=1:220)
  6. at j (jquery.min.self-6806c88afe0840c35208894c4ceba911154f696b624614b30b884298c2c3e00d.js?body=1:3)
  7. at Object.fireWith [as resolveWith] (jquery.min.self-6806c88afe0840c35208894c4ceba911154f696b624614b30b884298c2c3e00d.js?body=1:3)
  8. at Function.ready (jquery.min.self-6806c88afe0840c35208894c4ceba911154f696b624614b30b884298c2c3e00d.js?body=1:3)
  9. at HTMLDocument.I (jquery.min.self-6806c88afe0840c35208894c4ceba911154f696b624614b30b884298c2c3e00d.js?body=1:3)
  10.  
  11. 13:10:27:369 (ScrollScene) -> ERROR: Element defined in option "triggerElement" was not found: #section-6
  12.  
  13. 13:10:27:373 (ScrollScene) -> ERROR: Element defined in option "triggerElement" was not found: #section-6
  14.  
  15. 13:10:27:373 (ScrollScene) -> ERROR: Invalid value for option "triggerHook": .charger
  16.  
  17. 13:10:27:374 (ScrollScene) -> ERROR: Element defined in option "triggerElement" was not found: #section-7
  18.  
  19. 13:10:27:375 (ScrollScene) -> ERROR: Element defined in option "triggerElement" was not found: #section-7

它让我觉得完全相同的代码与完全相同的库似乎不适用于我的Ruby on Rails应用程序,它为什么?

错误不是函数发生,因为代码无法识别,通常这是因为未加载库.然而,在加载了te页面并加载了所有库之后,我检查了源页面.

TweenMax错误也是我的幻想,因为它是相同的库和相同的代码.

我已经尝试了几种解决方案,比如将库代码添加到我的script.js中,它似乎有效,但这将是一个不正确的解决方案.

我想我已经都需要信息和代码了,但是如果你还需要更多信息和代码.

总结一下我的问题:

问题:我的Jquery库似乎不起作用

问题:为什么?

的script.js

  1. //MENU
  2.  
  3. var wrap = $("#main-nav-bar");
  4.  
  5. wrap.on("scroll",function(e) {
  6. if (this.scrollTop > 147) {
  7. wrap.addClass("fix-search");
  8. } else {
  9. wrap.removeClass("fix-search");
  10. }
  11. });
  12.  
  13. //MENU END
  14.  
  15. //TWEENMAX
  16.  
  17. /* triggerHook: "onEnter" "onLeave" "onCenter"; */
  18. var controller = new ScrollMagic();
  19.  
  20. // Section 6
  21. new ScrollScene({
  22. triggerElement: "#section-6",duration: 300,triggerHook: 0.2
  23. })
  24. .setTween(TweenMax.to(".charging",1,{ opacity: "1" }))
  25. .addTo(controller);
  26.  
  27. new ScrollScene({
  28. triggerElement: "#section-6",duration: 600,triggerHook: ".charger"
  29. })
  30. .setTween(TweenMax.to(".charger",{ top: "766px" }))
  31. .addTo(controller);
  32.  
  33. new ScrollScene({
  34. triggerElement: "#section-7",duration: 200,triggerHook: 0.7
  35. })
  36. .setTween(TweenMax.to(".red-light",{ opacity: "1" }))
  37. .addTo(controller);
  38.  
  39. new ScrollScene({
  40. triggerElement: "#section-7",duration: 400,triggerHook: 0.5
  41. })
  42. .setTween(TweenMax.to(".front-phone",{ opacity: "1" }))
  43. .addTo(controller);
  44.  
  45. //TWEENMAX END
  46.  
  47. //PARALLAX
  48.  
  49. (function() {
  50. var parallax = document.querySelectorAll(".parallax"),speed = 0.3;
  51.  
  52. window.onscroll = function() {
  53. [].slice.call(parallax).forEach(function(el,i) {
  54. var windowYOffset = window.pageYOffset,elBackgrounPos = "0 " + windowYOffset * speed + "px";
  55.  
  56. el.style.backgroundPosition = elBackgrounPos;
  57. });
  58. };
  59. })();
  60.  
  61. // END PARALLAX
  62.  
  63. //Scrolling
  64.  
  65. $(document).ready(function() {
  66. //$("body").smoothWheel();
  67. });
  68.  
  69. (function($) {
  70. var self = this,container,running = false,currentY = 0,targetY = 0,oldY = 0,maxScrollTop = 0,minScrollTop,direction,onRenderCallback = null,fricton = 0.96,// higher value for slower deceleration
  71. vy = 0,stepAmt = 1,minMovement = 0.1,ts = 0.1;
  72.  
  73. var updateScrollTarget = function(amt) {
  74. targetY += amt;
  75. vy += (targetY - oldY) * stepAmt;
  76.  
  77. oldY = targetY;
  78. };
  79. var render = function() {
  80. if (vy < -minMovement || vy > minMovement) {
  81. currentY = currentY + vy;
  82. if (currentY > maxScrollTop) {
  83. currentY = vy = 0;
  84. } else if (currentY < minScrollTop) {
  85. vy = 0;
  86. currentY = minScrollTop;
  87. }
  88.  
  89. container.scrollTop(-currentY);
  90.  
  91. vy *= fricton;
  92.  
  93. // vy += ts * (currentY-targetY);
  94. // scrollTopTweened += settings.tweenSpeed * (scrollTop - scrollTopTweened);
  95. // currentY += ts * (targetY - currentY);
  96.  
  97. if (onRenderCallback) {
  98. onRenderCallback();
  99. }
  100. }
  101. };
  102. var animateLoop = function() {
  103. if (!running) return;
  104. requestAnimFrame(animateLoop);
  105. render();
  106. //log("45","animateLoop","",stop);
  107. };
  108. var onWheel = function(e) {
  109. e.preventDefault();
  110. var evt = e.originalEvent;
  111.  
  112. var delta = evt.detail ? evt.detail * -1 : evt.wheelDelta / 40;
  113. var dir = delta < 0 ? -1 : 1;
  114. if (dir != direction) {
  115. vy = 0;
  116. direction = dir;
  117. }
  118.  
  119. updateScrollTarget(delta);
  120. };
  121.  
  122. window.requestAnimFrame = (function() {
  123. return (
  124. window.requestAnimationFrame ||
  125. window.webkitRequestAnimationFrame ||
  126. window.mozRequestAnimationFrame ||
  127. window.oRequestAnimationFrame ||
  128. window.msRequestAnimationFrame ||
  129. function(callback) {
  130. window.setTimeout(callback,1000 / 60);
  131. }
  132. );
  133. })();
  134.  
  135. /*
  136. * http://jsbin.com/iqafek/2/edit
  137. */
  138. var normalizeWheelDelta = (function() {
  139. // Keep a distribution of observed values,and scale by the
  140. // 33rd percentile.
  141. var distribution = [],done = null,scale = 30;
  142. return function(n) {
  143. // Zeroes don't count.
  144. if (n == 0) return n;
  145. // After 500 samples,we stop sampling and keep current factor.
  146. if (done != null) return n * done;
  147. var abs = Math.abs(n);
  148. // Insert value (sorted in ascending order).
  149. outer: do {
  150. // Just used for break goto
  151. for (var i = 0; i < distribution.length; ++i) {
  152. if (abs <= distribution[i]) {
  153. distribution.splice(i,abs);
  154. break outer;
  155. }
  156. }
  157. distribution.push(abs);
  158. } while (false);
  159. // Factor is scale divided by 33rd percentile.
  160. var factor = scale / distribution[Math.floor(distribution.length / 3)];
  161. if (distribution.length == 500) done = factor;
  162. return n * factor;
  163. };
  164. })();
  165.  
  166. //END SCROLLING
  167.  
  168. //MOVING PHONE
  169. $.fn.smoothWheel = function() {
  170. // var args = [].splice.call(arguments,0);
  171. var options = jQuery.extend({},arguments[0]);
  172. return this.each(function(index,elm) {
  173. if (!("ontouchstart" in window)) {
  174. container = $(this);
  175. container.bind("mousewheel",onWheel);
  176. container.bind("DOMMouseScroll",onWheel);
  177. currentY = targetY = 0;
  178. minScrollTop =
  179. container.get(0).clientHeight - container.get(0).scrollHeight;
  180. if (options.onRender) {
  181. onRenderCallback = options.onRender;
  182. }
  183. if (options.remove) {
  184. log("122","smoothWheel","remove","");
  185. running = false;
  186. container.unbind("mousewheel",onWheel);
  187. container.unbind("DOMMouseScroll",onWheel);
  188. } else if (!running) {
  189. running = true;
  190. animateLoop();
  191. }
  192. }
  193. });
  194. };
  195.  
  196. //END MOVING PHONE
  197. })(jQuery);
  198.  
  199. //fade in
  200. var $animation_elements = $(".animation-element");
  201. var $window = $(window);
  202.  
  203. function check_if_in_view() {
  204. var window_height = $window.height();
  205. var window_top_position = $window.scrollTop();
  206. var window_bottom_position = window_top_position + window_height;
  207.  
  208. $.each($animation_elements,function() {
  209. var $element = $(this);
  210. var element_height = $element.outerHeight();
  211. var element_top_position = $element.offset().top;
  212. var element_bottom_position = element_top_position + element_height;
  213.  
  214. //check to see if this current container is within viewport
  215. if (
  216. element_bottom_position >= window_top_position &&
  217. element_top_position <= window_bottom_position
  218. ) {
  219. $element.addClass("in-view");
  220. } else {
  221. $element.removeClass("in-view");
  222. }
  223. });
  224. }
  225.  
  226. $window.on("scroll resize",check_if_in_view);
  227. $window.trigger("scroll");
  228.  
  229. var particles = true,particleDensity,options = {
  230. effectWeight: 1,outerBuffer: 1.08,elementDepth: 220
  231. };
  232.  
  233. $(document).ready(function() {
  234. $(".section-0").logosDistort(options);
  235.  
  236. if (particles) {
  237. particleDensity = window.outerWidth * 7.5;
  238. if (particleDensity < 13000) {
  239. particleDensity = 13000;
  240. } else if (particleDensity > 20000) {
  241. particleDensity = 20000;
  242. }
  243. return $("#particle-target").particleground({
  244. dotColor: "#1ec5ee",lineColor: "#0a4e90",density: particleDensity.toFixed(0),parallax: false
  245. });
  246. }
  247. });
  248.  
  249. $(document).ready(function() {
  250. /**
  251. * This part does the "fixed navigation after scroll" functionality
  252. * We use the jQuery function scroll() to recalculate our variables as the
  253. * page is scrolled/
  254. */
  255. $(window).scroll(function() {
  256. var window_top = $(window).scrollTop() + 12; // the "12" should equal the margin-top value for nav.stick
  257. var div_top = $("#nav-anchor").offset().top;
  258. if (window_top > div_top) {
  259. $("nav").addClass("stick");
  260. } else {
  261. $("nav").removeClass("stick");
  262. }
  263. });
  264.  
  265. /**
  266. * This part causes smooth scrolling using scrollto.js
  267. * We target all a tags inside the nav,and apply the scrollto.js to it.
  268. */
  269. $("nav a").click(function(evn) {
  270. evn.preventDefault();
  271. $("html,body").scrollTo(this.hash,this.hash);
  272. });
  273.  
  274. /**
  275. * This part handles the highlighting functionality.
  276. * We use the scroll functionality again,some array creation and
  277. * manipulation,class adding and class removing,and conditional testing
  278. */
  279. var aChildren = $("nav li").children(); // find the a children of the list items
  280. var aArray = []; // create the empty aArray
  281. for (var i = 0; i < aChildren.length; i++) {
  282. var aChild = aChildren[i];
  283. var ahref = $(aChild).attr("href");
  284. aArray.push(ahref);
  285. } // this for loop fills the aArray with attribute href values
  286.  
  287. $(window).scroll(function() {
  288. var windowPos = $(window).scrollTop(); // get the offset of the window from the top of page
  289. var windowHeight = $(window).height(); // get the height of the window
  290. var docHeight = $(document).height();
  291.  
  292. for (var i = 0; i < aArray.length; i++) {
  293. var theID = aArray[i];
  294. var divPos = $(theID).offset().top; // get the offset of the div from the top of page
  295. var divHeight = $(theID).height(); // get the height of the div in question
  296. if (windowPos >= divPos && windowPos < divPos + divHeight) {
  297. $("a[href='" + theID + "']").addClass("nav-active");
  298. } else {
  299. $("a[href='" + theID + "']").removeClass("nav-active");
  300. }
  301. }
  302.  
  303. if (windowPos + windowHeight == docHeight) {
  304. if (!$("nav li:last-child a").hasClass("nav-active")) {
  305. var navActiveCurrent = $(".nav-active").attr("href");
  306. $("a[href='" + navActiveCurrent + "']").removeClass("nav-active");
  307. $("nav li:last-child a").addClass("nav-active");
  308. }
  309. }
  310. });
  311. });
  312.  
  313. //smooth anchors
  314. // Select all links with hashes
  315. $('a[href*="#"]')
  316. // Remove links that don't actually link to anything
  317. .not('[href="#"]')
  318. .not('[href="#0"]')
  319. .click(function(event) {
  320. // On-page links
  321. if (
  322. location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
  323. &&
  324. location.hostname == this.hostname
  325. ) {
  326. // Figure out element to scroll to
  327. var target = $(this.hash);
  328. target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
  329. // Does a scroll target exist?
  330. if (target.length) {
  331. // Only prevent default if animation is actually gonna happen
  332. event.preventDefault();
  333. $('html,body').animate({
  334. scrollTop: target.offset().top
  335. },1000,function() {
  336. // Callback after animation
  337. // Must change focus!
  338. var $target = $(target);
  339. $target.focus();
  340. if ($target.is(":focus")) { // Checking if the target was focused
  341. return false;
  342. } else {
  343. $target.attr('tabindex','-1'); // Adding tabindex for elements not focusable
  344. $target.focus(); // Set focus again
  345. };
  346. });
  347. }
  348. }
  349.  
  350. });
  351.  
  352. //end smooth anchors

index.html.erb

  1. <div id="sidebar">
  2. <div id="nav-anchor"></div>
  3. <nav>
  4. <ul>
  5. <li>
  6. <a href="#section-1">
  7. <div class="ball"></div><span id="link">Top</span></a>
  8. </li>
  9. <li>
  10. <a href="#section-2">
  11. <div class="ball"></div><span id="link">Design</span></a>
  12. </li>
  13. <li>
  14. <a href="#section-4">
  15. <div class="ball"></div><span id="link">Vermogen</span></a>
  16. </li>
  17. <li>
  18. <a href="#section-7">
  19. <div class="ball"></div><span id="link">Iris scanner</span></a>
  20. </li>
  21. <li>
  22. <a href="#section-8">
  23. <div class="ball"></div><span id="link">Fingerprint Scanner</span></a>
  24. </li>
  25. <li>
  26. <a href="#section-5">
  27. <div class="ball"></div><span id="link">Camera</span></a>
  28. </li>
  29. <li>
  30. <a href="#section-6">
  31. <div class="ball"></div><span id="link">Batterij</span></a>
  32. </li>
  33. <li>
  34. <a href="#section-9">
  35. <div class="ball"></div><span id="link">Software</span></a>
  36. </li>
  37. </ul>
  38. </nav>
  39. </div>
  40.  
  41. <div class="section-0">
  42. <div class="phone-container">
  43. <div class="phone-front" id="layer-one"></div>
  44. </div>
  45. </div>
  46.  
  47. <section class="section-1 parallax parallax-1" id="section-1">
  48.  
  49.  
  50. <div class="container" id="section-1">
  51.  
  52.  
  53. <div class="text-block animation-element">
  54. <h1>De toekomst is nu</h1>
  55. <p>"De Volks Phone is een geweldig hi-end toestel voor een betaalbare prijs."<br> — "Telegraaf"</p><br>
  56. <div class="pre-order-button">
  57. <a href="#section-9"> Pre-order</a>
  58. </div>
  59. </div>
  60. </div>
  61.  
  62. </section>
  63. <section class="section-2" id="section-2">
  64. <div class="container">
  65. <div class="left-half" id="left-half-home">
  66. <div class="text-block animation-element">
  67.  
  68. <h1>“De perfecte balans tussen staal en glaswerk”</h1>
  69.  
  70. </div>
  71. </div>
  72. <div class="right-half" id="right-half-home">
  73. <div class="rear-phone animation-element bounce-up">
  74.  
  75. </div>
  76. </div>
  77. </div>
  78. </section>
  79. <section class="section-3 parallax parallax-2" id="section-3">
  80. <div class="container">
  81. <h1>Ons Volk</h1>
  82. </div>
  83. </section>
  84. <section class="section-4" id="section-4">
  85. <div class="container">
  86. <div class="top-part" id="left-half-home">
  87. <div class="text-block animation-element">
  88.  
  89. <h1>Beter. Sneller. Uniek.</h1>
  90.  
  91.  
  92. </div>
  93. </div>
  94. <div class="middle-part" id="right-half-home">
  95. <div class="rear-phone animation-element slide-right">
  96.  
  97. </div>
  98. </div>
  99. <div class="bottom-part">
  100. <div class="text-block ">
  101.  
  102. <ul>
  103.  
  104. <li class="spec-left">
  105. <h1>6GB</h1>
  106. <img src="http://sterntelecom.com/img/phones/ram-memory.png">
  107. <h4>RAM</h4></li>
  108.  
  109. <li class="spec-center">
  110.  
  111. <h1> 4.2 Mghz </h1>
  112. <img src="http://sterntelecom.com/img/phones/cpu.png">
  113. <h4>Deca core cpu</h4></li>
  114.  
  115. <li class="spec-right">
  116. <h1>64GB</h1>
  117. <<img src="http://sterntelecom.com/img/phones/hard-drive.png">
  118. <h4>Opslag</h4></li>
  119.  
  120. <li class="spec-right">
  121. <h1>5.5 Inch</h1>
  122. <img src="http://sterntelecom.com/img/phones/inch.png">-
  123. <h4>Scherm</h4></li>
  124. </ul>
  125.  
  126. </div>
  127. </div>
  128. </div>
  129. </section>
  130. <section class="section-7" id="section-7">
  131. <div class="container">
  132. <div class="intro-text">
  133. <h1>Wat science fiction was in nu werkelijkheid.</h1>
  134. <h2>Maak kennis met de ultra-moderne functie van uw Volks Phone: De irisscanner</h2>
  135. </div>
  136. <div class="red-light"></div>
  137. <div class="front-phone left-half" id="left-half-home">
  138. <div class="screen" id="screen-section-7">
  139. </div>
  140. </div>
  141. <div class="right-half" id="right-half-home">
  142. <div class=" animation-element ">
  143. <div class="text-block animation-element ">
  144.  
  145. <h1>Veilig</h1>
  146. <p>Elk iris vertoont een uniek patroon. Met de irisscanner bent u verzekerd van veiligheid.</p>
  147.  
  148. </div>
  149. <div class="text-block animation-element ">
  150.  
  151. <h1>Ook in het donker</h1>
  152. <p>Met de infrarood iris scanner herkent de Volks Phone uw irissen ook in het donker.</p>
  153.  
  154. </div>
  155. <!--<div class="text-block animation-element ">
  156.  
  157. <h1>High-end telefoon voor een Low prijs</h1>
  158. <p>"The volks is the rare kind of phone that I can recommend without reservations."<br> — The Verge</p>
  159.  
  160. </div>-->
  161. </div>
  162. </div>
  163. </div>
  164. </section>
  165. <section class="section-8" id="section-8">
  166. <div class="container">
  167. <div class="left-half" id="left-half-home">
  168. <div class="text-block">
  169.  
  170. <h1>Fingerprint scanner</h1><br>
  171. <p>Ontgrendel de Volks Phone binnen 0.4 seconden met met de super snelle vingerafdrukscanner</p>
  172.  
  173. </div>
  174. </div>
  175. <div class="right-half animation-element bounce-up" id="right-half-home">
  176.  
  177. </div>
  178. </div>
  179. </section>
  180. <section class="section-5" id="section-5">
  181. <div class="container">
  182. <div class="top-part" id="left-half-home">
  183. <div class="text-block">
  184.  
  185. <h1>Haarscherpe foto's</h1><br>
  186. <p>16-mp back-camera,13-mp front-camera.</p>
  187.  
  188. </div>
  189. </div>
  190. <div class="middle-part" id="right-half-home">
  191.  
  192.  
  193. </div>
  194. <div class="bottom-part">
  195. <div class="text-block animation-element bounce-up">
  196.  
  197. </div>
  198. </div>
  199. </div>
  200. </section>
  201. <section class="section-6" id="section-6">
  202. <div class="container">
  203. <div class="front-phone left-half" id="left-half-home">
  204. <div class="screen">
  205. <div class="animation-element charging" id="charging">
  206. <h1>Fast Charging</h1>
  207. <div class="animation-element battery"></div>
  208. </div>
  209. </div>
  210. </div>
  211. <div class="charger">
  212. </div>
  213. <div class="right-half" id="right-half-home">
  214. <div class=" animation-element bounce-up">
  215. <div class="text-block animation-element">
  216.  
  217. <h1>Groot</h1>
  218. <p>Met een capaciteit van 3250Mah biedt Volks u een bovengemiddeld batterij vermogen.</p>
  219.  
  220. </div>
  221. <div class="text-block animation-element">
  222.  
  223. <h1>Snel</h1>
  224. <p>Via de fast-charging functie is de Volks Phone binnen 45minuten volledig opgeladen
  225. </p>
  226.  
  227. </div>
  228. <div class="text-block animation-element">
  229.  
  230. <h1>Zuinig</h1>
  231. <p>De Deca-core processor zorgt ervoor dat het toestel alleen op volle energie presteert wanneer dat nodig is.
  232. </p>
  233.  
  234. </div>
  235. </div>
  236. </div>
  237. </div>
  238. </section>
  239. <section class="section-9" id="section-9">
  240. <div class="container">
  241. <div class="top-part" id="left-half-home">
  242. <div class="text-block animation-element">
  243.  
  244. <h1>Simpliciteit op z'n fijnst</h1>
  245. <p>"The volks is the rare kind of phone that I can recommend without reservations."<br> — The Verge</p>
  246. <div class="pre-order-button">
  247. <a href=""> Pre-order</a>
  248. </div>
  249. </div>
  250.  
  251. </div>
  252. <div class="middle-part" id="right-half-home">
  253. <div class="screens">
  254. </div>
  255. </div>
  256. </div>
  257. <div class="arrow-up">
  258. <a href="#section-1"><img src="http://sterntelecom.com/img/phones/arrowhead.png"></a>
  259. </div>
  260. </section>

更新(增加请求的文件)

的application.js

  1. // This is a manifest file that'll be compiled into including all the files listed below.
  2. // Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
  3. // be included in the compiled file accessible from http://example.com/assets/application.js
  4. // It's not advisable to add code directly here,but if you do,it'll appear at the bottom of the
  5. // the compiled file.
  6. //
  7. //= require jquery
  8. //= require jquery_ujs
  9. //= require spree/frontend
  10.  
  11. //= require_tree .
  12. //= require spree/frontend/spree_auth
  13. //= require spree/frontend/spree_braintree_vzero
  14.  
  15.  
  16.  
  17. //= require jquery
  18.  
  19. //= require jquery_ujs
  20.  
  21. //= require turbolinks
  22.  
  23. //= require_tree
  24.  
  25. //= require_jquery.min
  26.  
  27. //= require_jquery-3.2.1.min
  28.  
  29. //= require_jquery.easeScroll
  30.  
  31. //= require_jquery.logosDistort.min
  32.  
  33. //= require_jquery.particleground.min
  34.  
  35. //= require_jquery.jquery.scrollmagic.min
  36.  
  37.  
  38. //= require 'greensock/TweenLite'
  39. //= require 'greensock/easing/EasePack'
  40. //= require 'greensock/jquery.gsap.js'

_head.html.erb

  1. <Meta charset="utf-8">
  2. <title>Volks - Het volk's toestel</title>
  3. <Meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
  4. <Meta content="width=device-width,initial-scale=1.0,maximum-scale=1" name="viewport">
  5.  
  6. <link rel='stylesheet prefetch' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css'>
  7. <link rel='stylesheet prefetch' href='https://www.jqueryscript.net/demo/jQuery-Plugin-For-3D-Perspective-Transforms-On-Mousemove-logosDistort/assets/css/perspectiveRules.css'>
  8.  
  9. <%== Meta_data_tags %>
  10. <%= canonical_tag(current_store.url) %>
  11. <%= favicon_link_tag 'volks-logo.png' %>
  12. <%= stylesheet_link_tag 'spree/frontend/all',media: 'screen' %>
  13. <%= csrf_Meta_tags %>
  14.  
  15.  
  16. <%= javascript_include_tag 'spree/frontend/all' %>
  17.  
  18.  
  19. <!--[if lt IE 9]>
  20. <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6/html5shiv.min.js"></script>
  21. <![endif]-->
  22. <%= yield :head %>

更新2(更改了application.js文件)

  1. //= require jquery
  2.  
  3. //= require jquery_ujs
  4.  
  5. //= require turbolinks
  6.  
  7. //= require_jquery.min
  8.  
  9. //= require_jquery-3.2.1.min
  10.  
  11. //= require_jquery.easeScroll
  12.  
  13. //= require_jquery.logosDistort.min
  14.  
  15. //= require_jquery.particleground.min
  16.  
  17. //= require_jquery.jquery.scrollmagic.min
  18.  
  19.  
  20. //= require spree/frontend/spree_auth
  21. //= require spree/frontend/spree_braintree_vzero

回答

您可以在下面的答案中找到答案,但这不是答案的唯一部分.答案的最后一部分是在CSS中,我的身体发生了冲突,造成了部分错误.因此,如果您遇到同样的问题,请确保您的库已加载到适当的位置(对我而言)和正确的顺序.还要确保您的CSS不会导致任何错误.

解决方法

根据您粘贴的文件,库的加载顺序错误.我怀疑应该将以下行移动到application.js清单的末尾,以确保仅在所有jQuery插件之后才加载它.就像是:
  1. //= require jquery
  2. //= require jquery_ujs
  3. //= require turbolinks
  4. //= require_tree .

请注意,require_tree不保证加载自定义脚本的顺序.因此,如果一个脚本依赖于另一个脚本,您仍然可以最终解决这些问题.您应该尝试编写独立脚本,以便执行顺序无关紧要.如果您绝对必须编写彼此依赖的脚本,那么您应该倾向于手动在清单中以正确的顺序导入它们.

此外,您导入看起来错误.您似乎已导入jQuery三次.你应该粘贴< head>的内容在开发模式下在最终呈现的页面标记以确保它实际上正在工作.

  1. //= require_jquery.min <-- second import!
  2. //= require_jquery-3.2.1.min <-- third import!
  3. //= require_jquery.easeScroll
  4. //= require_jquery.logosDistort.min
  5. //= require_jquery.particleground.min
  6. //= require_jquery.jquery.scrollmagic.min

尝试:

  1. //= require jquery.easeScroll

当然,在将相关的宝石添加到Gemfile之后.

猜你在找的Ruby相关文章