【发布时间】:2016-08-08 03:10:07
【问题描述】:
我有一个 Rails 应用程序,我正在尝试在其中实现一些 jQuery。
我有两个脚本,一个在第一次加载时工作,一个需要重新加载。我在修改 application.js 中的 turbolinks 时遇到了问题。现在同样的问题发生在另一个脚本上。
有效的:
jQuery(document).ready(function($){
//set animation timing
var animationDelay = 5000,
//loading bar effect
barAnimationDelay = 3800,
barWaiting = barAnimationDelay - 3000, //3000 is the duration of the transition on the loading bar - set in the scss/css file
//letters effect
lettersDelay = 50,
//type effect
typeLettersDelay = 150,
selectionDuration = 500,
typeAnimationDelay = selectionDuration + 800,
//clip effect
revealDuration = 600,
revealAnimationDelay = 1500;
initHeadline();
那个不行的:
jQuery(document).ready(function($){
//if you change this breakpoint in the style.css file (or _layout.scss if you use SASS), don't forget to update this value as well
var MQL = 1170;
//primary navigation slide-in effect
if($(window).width() > MQL) {
var headerHeight = $('.box-header').height();
$(window).on('scroll',
{
previousTop: 0
},
...
...
以此类推。
为什么会这样? CSS 或调用它的页面是否有问题?
【问题讨论】:
-
你是如何修改
application.js中的turbolinks的? -
我重新排列了它,所以它是这样的: //= 需要 jquery //= 需要 jquery.turbolinks //= 需要 jquery_ujs //= 需要 turbolinks
-
如果你通过注释掉它的
require来完全禁用turbolinks会发生什么? -
它有效!所以 turbolinks 是罪魁祸首?
-
你使用的是什么版本的 Rails?
标签: javascript jquery ruby-on-rails