ppoffice / hexo-theme-icarus

A simple, delicate, and modern theme for the static site generator Hexo.
https://ppoffice.github.io/hexo-theme-icarus/
MIT License
6.36k stars 1.55k forks source link

animation.js causes URLs with hash to jump to wrong position #1115

Closed ppwwyyxx closed 2 years ago

ppwwyyxx commented 2 years ago

Describe the bug When I uses a url with hash, e.g. blog.com/article/#title (generated by https://github.com/hexojs/hexo-renderer-markdown-it/#automatic-headline-ids) , I expect browser to open the link and jump to a position where the title is at top of the page. But the actual position is not.

System and Environment The version and configuration of Hexo and Icarus.

To Reproduce Steps to reproduce the behavior, such as:

  1. Open an incognito chrome window
  2. Paste https://ppoffice.github.io/hexo-theme-icarus/uncategorized/%E8%87%AA%E5%AE%9A%E4%B9%89hexo%E6%A0%87%E7%AD%BE%E6%8F%92%E4%BB%B6/#icon-1 in the new tab and press enter.

The position of the opened page sometimes does not end up at the desired hash position (though sometimes it works). It's easier to reproduce if I scroll up and down the opened page a little bit, open a new tab, paste URL, and press enter again.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots 2022-09-11_18-08

Additional context I found that animation.js may have caused this issue. I made the following change on my own website:

diff --git c/source/js/animation.js w/source/js/animation.js
index 50c7c3f..064cfd9 100644
--- c/source/js/animation.js
+++ w/source/js/animation.js
@@ -16,8 +16,12 @@
         $(selector).forEach(element => {
             element.style.transition = '0s';
             element.style.opacity = '0';
-            element.style.transform = 'scale(0.8)';
-            element.style.transformOrigin = 'center top';
+            if (!window.location.hash) {
+              element.style.transform = 'scale(0.8)';
+              element.style.transformOrigin = 'center top';
+            }
         });
     });
     setTimeout(() => {

Then I can get the expected behavior. However I don't understand the root cause.