原文及演示鏈接:https://bestzuo.cn/posts/446056512.html

image
這個(gè)其實(shí)還比較簡(jiǎn)單,只需要在主題目錄下next/source/js/src下面新建一個(gè)clicklove.js文件,當(dāng)然名字可以自己任取,然后在其中加入以下內(nèi)容:
/*網(wǎng)頁鼠標(biāo)點(diǎn)擊特效(愛心)*/
!function (e, t, a) {function r() {for (var e = 0; e < s.length; e++) s[e].alpha <= 0 ? (t.body.removeChild(s[e].el), s.splice(e, 1)) : (s[e].y--, s[e].scale += .004, s[e].alpha -= .013, s[e].el.style.cssText = "left:" + s[e].x + "px;top:" + s[e].y + "px;opacity:" + s[e].alpha + ";transform:scale(" + s[e].scale + "," + s[e].scale + ") rotate(45deg);background:" + s[e].color + ";z-index:99999");requestAnimationFrame(r)}function n() {var t = "function" == typeof e.onclick && e.onclick;e.onclick = function (e) {t && t(), o(e)}}function o(e) {var a = t.createElement("div");a.className = "heart", s.push({el: a,x: e.clientX - 5,y: e.clientY - 5,scale: 1,alpha: 1,color: c()}), t.body.appendChild(a)}function i(e) {var a = t.createElement("style");a.type = "text/css";try {a.appendChild(t.createTextNode(e))} catch (t) {a.styleSheet.cssText = e}t.getElementsByTagName("head")[0].appendChild(a)}function c() {return "rgb(" + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + "," + ~~(255 * Math.random()) + ")"}var s = [];e.requestAnimationFrame = e.requestAnimationFrame || e.webkitRequestAnimationFrame || e.mozRequestAnimationFrame || e.oRequestAnimationFrame || e.msRequestAnimationFrame || function (e) {setTimeout(e, 1e3 / 60)}, i(".heart{width: 10px;height: 10px;position: fixed;background: #f00;transform: rotate(45deg);-webkit-transform: rotate(45deg);-moz-transform: rotate(45deg);}.heart:after,.heart:before{content: '';width: inherit;height: inherit;background: inherit;border-radius: 50%;-webkit-border-radius: 50%;-moz-border-radius: 50%;position: fixed;}.heart:after{top: -5px;}.heart:before{left: -5px;}"), n(), r()}(window, document);
上面這個(gè)是鼠標(biāo)點(diǎn)擊出現(xiàn)小心心的文件,也可以加上鼠標(biāo)點(diǎn)擊出現(xiàn)社會(huì)主義核心價(jià)值觀的js文件,如果只想要一個(gè)就只加一個(gè)文件即可,在剛才的目錄下繼續(xù)創(chuàng)建clicksocialvalue.js文件,然后在文件中加入以下內(nèi)容:
(function() {
var coreSocialistValues = ["富強(qiáng)", "民主", "文明", "和諧", "自由", "平等", "公正", "法治", "愛國(guó)", "敬業(yè)", "誠(chéng)信", "友善"],
index = Math.floor(Math.random() * coreSocialistValues.length);
document.body.addEventListener('click',
function(e) {
//過濾a標(biāo)簽
if (e.target.tagName == 'A') {
return;
}
var x = e.pageX,
y = e.pageY,
span = document.createElement('span');
span.textContent = coreSocialistValues[index];
index = (index + 1) % coreSocialistValues.length;
span.style.cssText = ['z-index: 9999999; position: absolute; font-weight: bold; color: #ff6651; top: ', y - 20, 'px; left: ', x, 'px;'].join('');
document.body.appendChild(span);
animate(span);
});
當(dāng)然如果兩個(gè)都需要的話,可以直接將兩個(gè)文件的代碼合并到一個(gè)文件即可。
然后在主題目錄下next/layout/_layout.swig文件中的<body></body>體標(biāo)簽內(nèi)引入剛才創(chuàng)建的js文件:
{% include '_third-party/comments/index.swig' %}
<script type="text/javascript" src="/js/src/clicklove.js"></script>
<script type="text/javascript" src="/js/src/clicksocialvalue.js"></script>
然后只需要重新渲染頁面hexo g && hexo s就可以看到效果啦~