bennyxguo / hexo-theme-obsidian

🎨 A dark Hexo theme, it's responsive, simple but elegant.
https://obsidian.tridiamond.tech/
MIT License
778 stars 109 forks source link

Animation is slow with push, replace state #183

Open zhenyuan0502 opened 9 months ago

zhenyuan0502 commented 9 months ago

With Obsidian.js, I encountered the problem of animation is being slow and freezing if we do click to a paper in the home screen and back with multiple times, in such case, refresh the page would solve the problem, I am not quite sure how we can improve on it, here is the original code

    Obsidian.L(url, function (data) {
      if (!$(data).filter('#single').length) {
        location.href = url;
        return;
      }
      switch (flag) {
        case 'push':
          history.pushState(state, title, url);
          $('#preview').html($(data).filter('#single'));
          break;
        case 'replace':
          history.replaceState(state, title, url);
          $('#preview').html($(data).filter('#single'));
          break;
      }
      document.title = title;
      $('#preview').html($(data).filter('#single'));
      switch (flag) {
        case 'push':
          Obsidian.preview();
          break;
        case 'replace':
          Obsidian.initArticleJs();
          window.scrollTo(0, 0);
          Obsidian.loaded();
          break;
      }
      setTimeout(function () {
        Obsidian.player();
        $('#top').show();
        comment = $('#gitalk-container');
        if (comment.data('ae') == true) {
          comment.click();
        }
      }, 0);
    });

What I have temporarily done is wipe out all animation and focus on url page change only

Obsidian.L(url, function (data) {
      location.href = url;
}