简体   繁体   English

Rails 5,Turbolinks 5 JQuery停止在页面重新加载

[英]Rails 5, Turbolinks 5 JQuery Stops Working on Page Reload

I've seen this problem posted a few times on here, but none of the solutions work for me, including the one from the Rails Guide. 我已经看到这个问题在这里发布了几次,但没有一个解决方案适合我,包括Rails指南中的解决方案。 Is there something wrong with my code below that I'm missing? 我的代码下面有什么问题我错过了吗? Essentially, when a page initially loads, JQuery works, but when you reload the page, everything stops working. 本质上,当页面最初加载时,JQuery可以工作,但是当你重新加载页面时,一切都停止工作。 I'm a Rails noob so appreciate your help and patience. 我是一个Rails noob,所以感谢你的帮助和耐心。

app/javascripts/application.js 应用程序/ Javascript角/ application.js中

//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap-sprockets
//= bootstrap.min.js
//= require_tree .

$(document).on('ready turbolinks:load', function(){
    $(".full-width").fadeIn(2500);

    $(".index-thumbnails").hover(function(){
        $(this).animate({opacity: 0.60},"fast")
    },
    function(){
        $(this).animate({opacity: 1},"fast")
    });

    setTimeout(function(){
    $("#subscribeModal").modal("show"); 
    }, 
    5000
    );

    $(".close").on("click", function(){
        $("#subscribeModal").modal("hide");
    });

    $(".social").mouseover(
        function(){
          $(this).animate({height: 116, width: 116},"fast");
        }
    );

    $(".social").mouseout(
        function(){
          $(this).animate({height: 96, width: 96},"fast");
        }
    );

});

尝试$(document).on('turbolinks:load', function(){并将gem'jquery gem 'jquery-turbolinks'到你的gemfile。它会工作。检查并通知我。我认为这次应该可以工作。

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

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