老夫的毕生所学都在这里了

2020-03-25 15:10:02 +08:00
 zerision

都在分享博客,我也来搞一个 网址:http://www.zerision.fun 只求 B 站点个赞!

6798 次点击
所在节点    分享创造
35 条回复
zhouhua97
2020-03-25 15:42:52 +08:00
看了,不错,支持鼓励一下。
dovme
2020-03-25 15:46:44 +08:00
鼠标点击的特效请问怎么弄啊
tiantangtianma
2020-03-25 15:50:11 +08:00
点赞 楼主厉害已加入收藏夹 顺便 B 站地址没看到啊
zerision
2020-03-25 15:52:25 +08:00
影视的动漫是我 B 站的视频,没啥人看的
zerision
2020-03-25 15:54:36 +08:00
@dovme 代码:
// Click Effect
function clickEffect() {
let balls = [];
let longPressed = false;
let longPress;
let multiplier = 0;
let width, height;
let origin;
let normal;
let ctx;
const colours = ["#F73859", "#14FFEC", "#00E0FF", "#FF99FE", "#FAF15D"];
const canvas = document.createElement("canvas");
document.body.appendChild(canvas);
canvas.setAttribute("style", "width: 100%; height: 100%; top: 0; left: 0; z-index: 99999; position: fixed; pointer-events: none;");
const pointer = document.createElement("span");
pointer.classList.add("pointer");
document.body.appendChild(pointer);

if (canvas.getContext && window.addEventListener) {
ctx = canvas.getContext("2d");
updateSize();
window.addEventListener('resize', updateSize, false);
loop();
window.addEventListener("mousedown", function(e) {
pushBalls(randBetween(10, 20), e.clientX, e.clientY);
document.body.classList.add("is-pressed");
longPress = setTimeout(function() {
document.body.classList.add("is-longpress");
longPressed = true;
}, 500);
}, false);
window.addEventListener("mouseup", function(e) {
clearInterval(longPress);
if (longPressed == true) {
document.body.classList.remove("is-longpress");
pushBalls(randBetween(50 + Math.ceil(multiplier), 100 + Math.ceil(multiplier)), e.clientX, e.clientY);
longPressed = false;
}
document.body.classList.remove("is-pressed");
}, false);
window.addEventListener("mousemove", function(e) {
let x = e.clientX;
let y = e.clientY;
pointer.style.top = y + "px";
pointer.style.left = x + "px";
}, false);
} else {
console.log("canvas or addEventListener is unsupported!");
}


function updateSize() {
canvas.width = window.innerWidth * 2;
canvas.height = window.innerHeight * 2;
canvas.style.width = window.innerWidth + 'px';
canvas.style.height = window.innerHeight + 'px';
ctx.scale(2, 2);
width = (canvas.width = window.innerWidth);
height = (canvas.height = window.innerHeight);
origin = {
x: width / 2,
y: height / 2
};
normal = {
x: width / 2,
y: height / 2
};
}
class Ball {
constructor(x = origin.x, y = origin.y) {
this.x = x;
this.y = y;
this.angle = Math.PI * 2 * Math.random();
if (longPressed == true) {
this.multiplier = randBetween(14 + multiplier, 15 + multiplier);
} else {
this.multiplier = randBetween(6, 12);
}
this.vx = (this.multiplier + Math.random() * 0.5) * Math.cos(this.angle);
this.vy = (this.multiplier + Math.random() * 0.5) * Math.sin(this.angle);
this.r = randBetween(8, 12) + 3 * Math.random();
this.color = colours[Math.floor(Math.random() * colours.length)];
}
update() {
this.x += this.vx - normal.x;
this.y += this.vy - normal.y;
normal.x = -2 / window.innerWidth * Math.sin(this.angle);
normal.y = -2 / window.innerHeight * Math.cos(this.angle);
this.r -= 0.3;
this.vx *= 0.9;
this.vy *= 0.9;
}
}

function pushBalls(count = 1, x = origin.x, y = origin.y) {
for (let i = 0; i < count; i++) {
balls.push(new Ball(x, y));
}
}

function randBetween(min, max) {
return Math.floor(Math.random() * max) + min;
}

function loop() {
ctx.fillStyle = "rgba(255, 255, 255, 0)";
ctx.clearRect(0, 0, canvas.width, canvas.height);
for (let i = 0; i < balls.length; i++) {
let b = balls[i];
if (b.r < 0) continue;
ctx.fillStyle = b.color;
ctx.beginPath();
ctx.arc(b.x, b.y, b.r, 0, Math.PI * 2, false);
ctx.fill();
b.update();
}
if (longPressed == true) {
multiplier += 0.2;
} else if (!longPressed && multiplier >= 0) {
multiplier -= 0.4;
}
removeBall();
requestAnimationFrame(loop);
}

function removeBall() {
for (let i = 0; i < balls.length; i++) {
let b = balls[i];
if (b.x + b.r < 0 || b.x - b.r > width || b.y + b.r < 0 || b.y - b.r > height || b.r < 0) {
balls.splice(i, 1);
}
}
}
}
clickEffect()//调用
// End Click Effect
liqingcan
2020-03-25 15:55:28 +08:00
鼠标点击的特效请问怎么弄啊 +1
zerision
2020-03-25 15:59:05 +08:00
@liqingcan js 代码发出来了
star7th
2020-03-25 16:05:51 +08:00
一看这么花俏的肯定是小孩子
star7th
2020-03-25 16:06:24 +08:00
我说的是鼠标特效
liqingcan
2020-03-25 16:15:43 +08:00
@zerision 看到了。谢谢哈
zerision
2020-03-25 16:17:20 +08:00
@star7th 看个人兴趣吧,有人喜欢有人不喜欢
iRiven
2020-03-25 16:24:44 +08:00
鼠标特效太夸张,技术内容的还是不要和动漫内容放在一起
monkeydev
2020-03-25 16:28:49 +08:00
95 年居然自称老夫
那我是不是应该称自己老朽了哈哈哈
楼主棒棒哒
windychen0
2020-03-25 16:34:54 +08:00
随便点了个链接一看这么快,瞥了一眼我右上角的 VueDevtool 果然亮了[狗头]
otakustay
2020-03-25 16:54:50 +08:00
@monkeydev 不,我们是老不死
monkeydev
2020-03-25 17:05:31 +08:00
@otakustay
对对对,精神
xkxy
2020-03-25 17:30:21 +08:00
想问一下怎么把 B 站视频,嵌入网站呢?
xiri
2020-03-25 17:34:40 +08:00
@xdxtao b 站你点分享会有嵌入地址
qfdk
2020-03-25 17:43:05 +08:00
首页的轮播图变形 头疼 左上角关了。。
wangyuescr
2020-03-25 18:21:48 +08:00
只想知道这个微屁恩体验如何

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/656062

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX