what can i put in beforeUnload?

后端 未结 4 1323
被撕碎了的回忆
被撕碎了的回忆 2020-12-31 10:00

I would like to have an animation effect which starts when people leave a page.

I use this currently:

window.onbeforeunload = function (){
    alert         


        
4条回答
  •  鱼传尺愫
    2020-12-31 10:09

    Jorrebor, If your trying to have this animation fire when they leave your site or close the browser it will not work as intended. However, you can create this animation while the user travels within your site by removing the 'href' property of your links and creating animations that have a callback function that set the window.location property. Something like:

    document.getElementById('home').onclick(function(){
         yourAnimationFunction(function(){
              window.location="example.com";
         });  
    });
    

    alot of work and wont be seo friendly however

提交回复
热议问题