鼠标点击爱心和富强特效

爱心

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
!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);

富强

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//定义获取词语下标
var a_idx = 0;
jQuery(document).ready(function($) {
//点击body时触发事件
$("body").click(function(e) {
//需要显示的词语
var a = new Array("富强","民主", "文明", "和谐","自由", "平等", "公正","法治", "爱国", "敬业","诚信", "友善");
//设置词语给span标签
var $i = $("<span/>").text(a[a_idx]);
//下标等于原来下标+1 余 词语总数
a_idx = (a_idx + 1)% a.length;
//获取鼠标指针的位置,分别相对于文档的左和右边缘。
//获取x和y的指针坐标
var x = e.pageX, y = e.pageY;
//在鼠标的指针的位置给$i定义的span标签添加css样式
$i.css({"z-index" : 999999999999999999999999999999999999999999999999999999999999999999999,
"top" : y - 20,
"left" : x,
"position" : "absolute",
"font-weight" : "bold",
"color" : "#ff6651"
});
//在body添加这个标签
$("body").append($i);
//animate() 方法执行 CSS 属性集的自定义动画。
//该方法通过CSS样式将元素从一个状态改变为另一个状态。CSS属性值是逐渐改变的,这样就可以创建动画效果。
//详情请看http://www.w3school.com.cn/jquery/effect_animate.asp
$i.animate({
//将原来的位置向上移动180
"top" : y - 180,
"opacity" : 0
//1500动画的速度
}, 1500, function() {
//时间到了自动删除
$i.remove();
});
});
});

加入收藏

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// <a href="javascript:void(0)" onclick="shoucang(document.title,window.location)">加入收藏</a>

function shoucang(sTitle, sURL) {
try {
window.external.addFavorite(sURL, sTitle);
}
catch (e) {
try {
window.sidebar.addPanel(sTitle, sURL, "");
}
catch (e) {
alert("加入收藏失败,请使用Ctrl+D进行添加");
}
}
}

设为首页

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// <a href="javascript:void(0)" onclick="SetHome(this,window.location)">设为首页</a>

function SetHome(obj, vrl) {
try {
obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
}
catch (e) {
if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
}
catch (e) {
alert("此操作被浏览器拒绝!\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。");
}
var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setCharPref('browser.startup.homepage', vrl);
} else {
alert("您的浏览器不支持,请按照下面步骤操作:1.打开浏览器设置。2.点击设置网页。3.输入:" + vrl + "点击确定。");
}
}
}

图片不存在显示默认图片

  • 分析:特别注意 onerror,当图片不存在时,将触发 onerror,而 onerror 中为 img 指定一个默认图片。也就是说图片存在则显示 pic.gif,图片不存在将显示默认图片。

  • 存在的问题:如果默认图片也不存在,则继续触发 onerror,导致循环,故出现错误。如果图片存在,但网络很不通畅,也可能触发 onerror。

    1
    2
    3
    4
    5
    6
    7
    8
    <img src="abc.jpg" οnerrοr="nofind()" />
    <script type="text/javascript">
    function nofind(){
    var img=event.srcElement;
    img.src="def"; //替换的图片
    img.οnerrοr=null; //控制不要一直触发错误
    }
    </script>
本文结束感谢您的阅读

本文标题:鼠标点击爱心和富强特效

文章作者:陈宇(cosyer)

发布时间:2020年04月07日 - 23:04

最后更新:2020年04月11日 - 12:04

原始链接:http://mydearest.cn/2020/%E9%BC%A0%E6%A0%87%E7%82%B9%E5%87%BB%E7%88%B1%E5%BF%83%E5%92%8C%E5%AF%8C%E5%BC%BA%E7%89%B9%E6%95%88.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

坚持原创技术分享,您的支持将鼓励我继续创作!