- website-content/:官网 10 篇文档内容 + README - website-design/:官网设计稿、动画实验、预览图与资源 - 根目录官网截图两张 - .gitignore 忽略 website-design/exp/static/dist 构建产物(7.1MB)
56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
/* Astrion 官网 C —— 交互(形象 / scrollspy / 复制) */
|
||
|
||
(function () {
|
||
'use strict';
|
||
|
||
AstrionAvatar.mount(document.getElementById('sideAvatar'), { mode: 'idle', blink: true, track: true });
|
||
|
||
/* scrollspy:目录高亮当前章节 */
|
||
var links = Array.prototype.slice.call(document.querySelectorAll('.toc-item'));
|
||
var chapters = links
|
||
.map(function (a) { return document.querySelector(a.getAttribute('href')); })
|
||
.filter(Boolean);
|
||
|
||
var spy = new IntersectionObserver(function (entries) {
|
||
entries.forEach(function (e) {
|
||
if (!e.isIntersecting) return;
|
||
links.forEach(function (a) {
|
||
a.classList.toggle('current', a.getAttribute('href') === '#' + e.target.id);
|
||
});
|
||
});
|
||
}, { rootMargin: '-20% 0px -65% 0px' });
|
||
|
||
chapters.forEach(function (c) { spy.observe(c); });
|
||
|
||
/* 复制按钮:固定尺寸,只换图标 */
|
||
document.querySelectorAll('[data-copy]').forEach(function (btn) {
|
||
var timer = null;
|
||
btn.addEventListener('click', function () {
|
||
var block = btn.parentElement.querySelector('pre code');
|
||
var text = block ? block.textContent : '';
|
||
function mark() {
|
||
btn.classList.add('copied');
|
||
clearTimeout(timer);
|
||
timer = setTimeout(function () { btn.classList.remove('copied'); }, 1600);
|
||
}
|
||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||
navigator.clipboard.writeText(text).then(mark, function () { fallback(text); mark(); });
|
||
} else {
|
||
fallback(text);
|
||
mark();
|
||
}
|
||
});
|
||
});
|
||
|
||
function fallback(text) {
|
||
var ta = document.createElement('textarea');
|
||
ta.value = text;
|
||
ta.style.position = 'fixed';
|
||
ta.style.opacity = '0';
|
||
document.body.appendChild(ta);
|
||
ta.select();
|
||
try { document.execCommand('copy'); } catch (e) {}
|
||
document.body.removeChild(ta);
|
||
}
|
||
})();
|