summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBigCoke233 <hi@guhub.cn>2020-04-15 18:01:08 +0800
committerBigCoke233 <hi@guhub.cn>2020-04-15 18:01:08 +0800
commit02af96794734b2ed8431eeefe5a4fc8e56c67224 (patch)
tree7ada9fe281c3af8c17f45f190ed0a26f8740c982
parent3def1ca01fc20e6f6da887182202f10047e3a912 (diff)
:bird: Perf: 平滑的锚点动画
-rw-r--r--assets/js/miracles.min.js15
-rw-r--r--libs/Contents.php5
2 files changed, 18 insertions, 2 deletions
diff --git a/assets/js/miracles.min.js b/assets/js/miracles.min.js
index 1b6eb89..1db4b4c 100644
--- a/assets/js/miracles.min.js
+++ b/assets/js/miracles.min.js
@@ -142,13 +142,25 @@ $('#gotop').hide();
$(window).scroll(function() {
if ($(window).scrollTop() > 450) {
scaleIn($('#gotop'), '0.7');
- scaleIn($('#gotop'), '0.7');
} else {
scaleOut($('#gotop'), '0.7');
}
});
/**
+ * Anchor Link Animation
+ */
+function anchorAniLoad(){
+ $('a[href^="#"]').click(function(){
+ $('html, body').animate({
+ scrollTop: $($.attr(this, 'href')).offset().top
+ }, 400);
+ return false;
+ });
+}
+anchorAniLoad();
+
+/**
* Js Loader
*/
//LazyLoad
@@ -504,6 +516,7 @@ if (loadPjax = true) {
navColor();
//Link
linkTarget();
+ anchorAniLoad();
//comment
MiraclesComment.bindReplyBtn(); //Bind Reply Button
MiraclesComment.core(); //Comment Core
diff --git a/libs/Contents.php b/libs/Contents.php
index 75aa833..256ff46 100644
--- a/libs/Contents.php
+++ b/libs/Contents.php
@@ -229,7 +229,10 @@ class Contents
static public function parseHeaderCallback($matchs)
{
// 增加单独标记,否则冲突
- $id = 'toc_'.(self::$CurrentTocID++);
+ $id = $matchs[3];
+ $id = str_replace(' ','\%20',$id);
+ $id = str_replace('&','\%26',$id);
+ $id = str_replace('?','\%3F;',$id);
return '<h'.$matchs[1].$matchs[2].' id="'.$id.'">'.$matchs[3].'<a href="#'.$id.'" title="章节链接" class="post-toc-link no-line"><i class="iconfont icon-paragraph"></i></a></h'.$matchs[1].'>';
}