From 24ef0d2a0c9483879c195a76e77a477db3f6ca72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=98=94=E8=90=BD?= <45323514+BigCoke233@users.noreply.github.com> Date: Sat, 30 Mar 2019 15:31:58 +0800 Subject: Add files via upload --- assets/js/id-transition.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 assets/js/id-transition.js (limited to 'assets/js') diff --git a/assets/js/id-transition.js b/assets/js/id-transition.js new file mode 100644 index 0000000..9355b69 --- /dev/null +++ b/assets/js/id-transition.js @@ -0,0 +1,18 @@ + $(function(){ + //锚点跳转滑动效果 + $('a[href*=#],area[href*=#]').click(function() { + console.log(this.pathname) + if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) { + var $target = $(this.hash); + $target = $target.length && $target || $('[name=' + this.hash.slice(1) + ']'); + if ($target.length) { + var targetOffset = $target.offset().top; + $('html,body').animate({ + scrollTop: targetOffset + }, + 1000); + return false; + } + } + }); + }) -- cgit v1.2.3