我知道这个问题已经被问死了,但我仍然不能解决我的应用程序中的问题。我正在运行一个rails 5应用程序(带有turbolinks和fancybox lightbox gem),并使用一些特定于页面的javascript在模型显示页面上显示图像:
application.html.erb
<head>
...
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
...
</head>
<body>
...
<%= yield :page_scripts %>
</body>show.html.erb
<% content_for :page_scripts do %>
<script type="text/javascript">
$(document).on('turbolinks:load', function() {
$("a.fancybox").fancybox();
})
</script>
<% end %>我仍然得到了经典的响应,即图像在第一次页面访问或页面刷新时加载得很好。来回导航会使lightbox停止工作(似乎只是在我的情况下挂起)。
我如何使用'turbolinks:load‘功能让它正常工作?
发布于 2018-05-01 04:18:51
只需使用{parent: 'body'},它将解决Turbolink的问题。
$("a.fancybox").fancybox({parent: 'body'});发布于 2017-08-03 10:39:46
你可以改成下面的代码。
$(document).ready(function() {
document.addEventListener("turbolinks:load", function() {
$("a.fancybox").fancybox();
})
});我希望这对你有帮助。您可以通过此链接turbolinks转到详细信息。
发布于 2017-08-03 13:51:13
我不确定这是否完全有资格作为一个答案,但考虑到这个链接中的场景非常相似:
https://github.com/fancyapps/fancybox/issues/1413
....I最终听从了他们的建议,使用data- turbolinks ="false“从显示页面中删除了turbolinks。
https://stackoverflow.com/questions/45473522
复制相似问题