转载整合节选自 鼠标点击特效和鼠标跟随特效 &给WordPress添加评论输入特效

喜欢本文章还请去原作者博客里浏览留言

1.鼠标点击特效

将下面插入到主题文件夹 footer.php 的最后</body>

<script type="text/javascript">
	onload = function() {
    var click_cnt = 0;
    var $html = document.getElementsByTagName("html")[0];
    var $body = document.getElementsByTagName("body")[0];
    $html.onclick = function(e) {
        var $elem = document.createElement("b");
        $elem.style.color = "#E94F06";
        $elem.style.zIndex = 9999;
        $elem.style.position = "absolute";
        $elem.style.select = "none";
        var x = e.pageX;
        var y = e.pageY;
        $elem.style.left = (x - 10) + "px";
        $elem.style.top = (y - 20) + "px";
        clearInterval(anim);
        switch (++click_cnt) {
            case 10:
                $elem.innerText = "富强";
                break;
            case 20:
                $elem.innerText = "民主๑)";
                break;
            case 30:
                $elem.innerText = "文明";
                break;
            case 40:
                $elem.innerText = "和谐๑)";
                break;
            case 50:
                $elem.innerText = "自由";
                break;
            case 60:
                $elem.innerText = "平等";
                break;
            case 70:
                $elem.innerText = "公正)ა";
                break;
            case 80:
                $elem.innerText = "法制";
                break;
            case 90:
                $elem.innerText = "爱国₌₃";
                break;
            case 100:
            	$elem.innerText = "敬业";
                break;
            case 101:
            	$elem.innerText = "诚信";
                break;
            case 102:
            	$elem.innerText = "友善";
                break;
            case 103:
            case 104:
            case 105:
            default:
                $elem.innerText = "❤";
                break;
        }
        $elem.style.fontSize = Math.random() * 10 + 8 + "px";
        var increase = 0;
        var anim;
        setTimeout(function() {
            anim = setInterval(function() {
                if (++increase == 150) {
                    clearInterval(anim);
                    $body.removeChild($elem);
                }
                $elem.style.top = y - 20 - increase + "px";
                $elem.style.opacity = (150 - increase) / 120;
            }, 8);
        }, 70);
        $body.appendChild($elem);
    };
};
</script>

保存即可查看效果

2. 鼠标跟随特效

安装 wordpress 插件“canvas-nest ”,安装启用就可以了

3. 给WordPress添加评论输入特效

本站使用了评论输入特效,打字时有礼花绽放效果,并且可以设置震动(本站关闭了震动)。详细效果你去发表一下评论就知道了。

实现方法:

1、下载JS文件: 下载地址
2、 将下面插入到主题文件夹 footer.php 的最后</body>
<script src="<?php bloginfo('template_directory'); ?>/js/activate-power-mode.js "></script>
<script>
POWERMODE.colorful = true; // ture 为启用礼花特效
POWERMODE.shake = false; // false 为禁用震动特效
document.body.addEventListener('input', POWERMODE);
</script>

输入特效只有在评论的时候有用,为了不乱加载这些JS文件,建议给代码加一个判断,是文章页或页面的话才加载这些代码。

<?php if (is_single() || is_page() ) { ?>
<script src="<?php bloginfo('template_directory'); ?>/js/activate-power-mode.js "></script>
<script>
POWERMODE.colorful = true; // ture 为启用礼花特效
POWERMODE.shake = false; // false 为禁用震动特效
document.body.addEventListener('input', POWERMODE);
</script>
<?php }?>

注意/js/activate-power-mode.js记得根据实际情况修改activate-power-mode.js文件的调用路径。

注意*这是一则由 Google AdSense 自动推荐的广告,不代表本站立场