Javascript Rails 4 turbolinks页面:使用JS加载
我的应用程序中有以下基本JavaScript(CoffeeScript)Javascript Rails 4 turbolinks页面:使用JS加载,javascript,ruby-on-rails,ruby-on-rails-4,Javascript,Ruby On Rails,Ruby On Rails 4,我的应用程序中有以下基本JavaScript(CoffeeScript) window.onload = -> menu = document.getElementById("menu") wrapper = document.getElementById("wrapper") toggleMenu = false menu.onclick = -> if toggleMenu is false wrapper.style.left = "278
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('load',function(){…})代码>??
document.addEventListener('page:change', function(){
console.log('called')
});
# page reloaded, no clicks yet
=> called
# click turbolinks link
=> called