[英]Rails 4 turbolinks page:load with JS
我的应用程序中具有以下基本JavaScript(CoffeeScript)
window.onload = ->
menu = document.getElementById("menu")
wrapper = document.getElementById("wrapper")
toggleMenu = false
menu.onclick = ->
if toggleMenu is false
wrapper.style.left = "278px"
toggleMenu = true
else
wrapper.style.left = "0px"
toggleMenu = false
当您单击带有Turbolink的内容时,它将停止工作。
我在SO上找到了此解决方案,但不知道如何在JavaScript中实现它:
$(document).on('page:change', function () {
// Actions to do
});
我确实尝试了document.onchange,但没有成功。 为此,纯JavaScript解决方案是什么?
document.addEventListener('page:change', function(){
console.log('called')
});
# page reloaded, no clicks yet
=> called
# click turbolinks link
=> called
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.