先祝大家情人节快乐鸭!(虽然F1@g并没有对象
F1@g美化博客的过程是一个很艰辛的过程,因为隔壁的Endcat不完全给它白嫖,而是一点点的帮助它完成,所以F1@g花费了三天时间完成美化工作。本文主要是帮助各位小伙伴省去白嫖的过程,美化自己的博客。
一、主题
一个好看的博客当然要有一个好看的主题鸭,在这里强烈推荐Mashiro的Sakura主题,真的是很好看呢。当然有能力的巨佬也可以自己写主题,如果你也选择使用了这个主题,这个视频:wordpress-akina主题使用教程可能会帮到你一些。
二、博客页面动态雪花效果
不知道有没有细心的小伙伴发现F1@g的博客其实是有雪花效果的,其实雪花效果很简单的,具体只需要新建一个画布,引用js代码,在style里加写东西就好啦。
新建画布并引用js
对于啥也不会的小白(比如F1@g)来说,如果F1@g直接说建画布然后引用js不给出任何代码的话,可能对于小白来说过于抽象,在此F1@g秉承傻瓜教程的原则,请在footer.php中随意位置添加以下两行代码:
<canvas id="Snow"></canvas>
<script src="http://39.108.11.206/wp-content/themes/Sakura/snow.js"></script><!--请读者将此目录改成自己对应的目录-->
然后将以下代码保存为snow.js放入对应目录
(function() {
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame ||
function(callback) {
window.setTimeout(callback, 1000 / 60);
};
window.requestAnimationFrame = requestAnimationFrame;
})();
(function() {
var flakes = [],
canvas = document.getElementById("Snow"), //画布ID,与上一步创建的画布对应
ctx = canvas.getContext("2d"),
flakeCount = 200, //雪花数量,数值越大雪花数量越多
mX = -100,
mY = -100;
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
function snow() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (var i = 0; i < flakeCount; i++) {
var flake = flakes[i],
x = mX,
y = mY,
minDist = 150, //雪花距离鼠标指针的最小值,小于这个距离的雪花将受到鼠标的排斥
x2 = flake.x,
y2 = flake.y;
var dist = Math.sqrt((x2 - x) * (x2 - x) + (y2 - y) * (y2 - y)),
dx = x2 - x,
dy = y2 - y;
if (dist < minDist) {
var force = minDist / (dist * dist),
xcomp = (x - x2) / dist,
ycomp = (y - y2) / dist,
deltaV = force / 2;
flake.velX -= deltaV * xcomp;
flake.velY -= deltaV * ycomp;
} else {
flake.velX *= .98;
if (flake.velY <= flake.speed) { flake.velY = flake.speed } flake.velX += Math.cos(flake.step += .05) * flake.stepSize; } ctx.fillStyle = "rgba(255,255,255," + flake.opacity + ")"; //雪花颜色 flake.y += flake.velY; flake.x += flake.velX; if (flake.y >= canvas.height || flake.y <= 0) { reset(flake); } if (flake.x >= canvas.width || flake.x <= 0) {
reset(flake);
}
ctx.beginPath();
ctx.arc(flake.x, flake.y, flake.size, 0, Math.PI * 2);
ctx.fill();
}
requestAnimationFrame(snow);
};
function reset(flake) {
flake.x = Math.floor(Math.random() * canvas.width);
flake.y = 0;
flake.size = (Math.random() * 3) + 2; //加号后面的值,雪花大小,为基准值,数值越大雪花越大
flake.speed = (Math.random() * 1) + 0.5; //加号后面的值,雪花速度,为基准值,数值越大雪花速度越快
flake.velY = flake.speed;
flake.velX = 0;
flake.opacity = (Math.random() * 0.5) + 0.3; //加号后面的值,为基准值,范围0~1
}
function init() {
for (var i = 0; i < flakeCount; i++) {
var x = Math.floor(Math.random() * canvas.width),
y = Math.floor(Math.random() * canvas.height),
size = (Math.random() * 3) + 2, //加号后面的值,雪花大小,为基准值,数值越大雪花越大
speed = (Math.random() * 1) + 0.5, //加号后面的值,雪花速度,为基准值,数值越大雪花速度越快
opacity = (Math.random() * 0.5) + 0.3; //加号后面的值,为基准值,范围0~1
flakes.push({
speed: speed,
velY: speed,
velX: 0,
x: x,
y: y,
size: size,
stepSize: (Math.random()) / 30 * 1, //乘号后面的值,雪花横移幅度,为基准值,数值越大雪花横移幅度越大,0为竖直下落
step: 0,
angle: 180,
opacity: opacity
});
}
snow();
};
document.addEventListener("mousemove", function(e) {
mX = e.clientX,
mY = e.clientY
});
window.addEventListener("resize", function() {
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
});
init();
})();
在style.css中添加以下内容
#Snow{
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 99999;
background: rgba(125,137,95,0.1);
pointer-events: none;
}
刷新以下就能看到漂亮的雪花了!还有鼠标排斥的小惊喜呢
三、鼠标点击爱心特效
将以下代码直接粘贴到footer.php里就可以了
<script>
!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);
></script>
效果在本站即可测试
四、在鼠标旁添加随机折线
这里用到一个叫做Canvas-Nest.js的插件,直接在后台下载启用即可。
五、在标签页添加检测是否阅读本页细节
不知道小伙伴们发没发现你在看这页时和不看这页是标签页上的文字是不一样的呢,那么这个是怎么实现的呢,其实很简单,将下面代码保存为js并引用即可:
var OriginTitile = document.title;
var hidden, state, visibilityChange;
//兼容所有浏览器(除ie
if(typeof document.hidden !== "undefined") {
hidden = "hidden";
visibilityChange = "visibilitychange";
state = "visibilityState";
} else if(typeof document.mozHidden !== "undefined") {
hidden = "mozHidden";
visibilityChange = "mozvisibilitychange";
state = "mozVisibilityState";
} else if(typeof document.msHidden !== "undefined") {
hidden = "msHidden";
visibilityChange = "msvisibilitychange";
state = "msVisibilityState";
} else if(typeof document.webkitHidden !== "undefined") {
hidden = "webkitHidden";
visibilityChange = "webkitvisibilitychange";
state = "webkitVisibilityState";
}
//新建事件检测
document.addEventListener(visibilityChange, function() {
if (document[state] === "hidden"){
document.title = "藏好了!qaq";//在这里修改未查看本页时的提示
}else {
document.title = '被找到了(*/ω\*)-' + OriginTitile;//在这里修改查看本页时的提示
}
}, false);
//初始化标题
OriginTitile = document.title;
Comments | NOTHING