富强民主文明和谐 点击事件变颜色

复制下面的代码建立一个html文件就能运行了。如果在想加在自己的博客园里面,直接把js部分加在后台就行了。


这个代码是在网上很容易搜到的这个代码中仅仅加了一个换颜色的小功能。

<html>
	<head>
		<title>我的特效</title>
		<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
	</head>
	<body>
		<h2>I love you !</h2>
	</body>
	<script type="text/javascript"> 
/* 鼠标特效 */
var a_idx = 0; 
jQuery(document).ready(function($) { 
    $("body").click(function(e) { 
        var a = new Array("富强", "民主", "文明", "和谐", "自由", "平等", "公正" ,"法治", "爱国", "敬业", "诚信", "友善"); 
		var b = new Array("red","blue","yellow","green","pink","blue","orange");
        var $i = $("<span/>").text(a[a_idx]); 
        a_idx = (a_idx + 1) % a.length; 
		b_idx = (a_idx+1)%7;/* 七中颜色变色 */
        var x = e.pageX, 
        y = e.pageY; 
        $i.css({ 
            "z-index": 9999, 
            "top": y - 20, 
            "left": x, 
            "position": "absolute", 
            "font-weight": "bold", 
            "color": b[b_idx]
        }); 
        $("body").append($i); 
        $i.animate({ 
            "top": y - 180, 
            "opacity": 0 
        }, 
        1500, 
        function() { 
            $i.remove(); 
        }); 
    }); 
}); 
</script>
</html>
posted @ 2019-09-15 18:45  吴雄  阅读(387)  评论(0编辑  收藏  举报