html %3chr %3e样式,music.html

该博客介绍了如何使用JavaScript实现网页上的动态效果,包括生成飘落的雪花和鼠标点击后的彩色球体扩散效果。通过设置不同的参数,如字体大小、颜色、透明度和飘落速度,创建了视觉上吸引人的交互体验。这些特效可以增强用户的浏览体验,为网页增添趣味性。
摘要由CSDN通过智能技术生成
geekswg-我的主页 博客

// 生成雪花 js代码

window.onload = function () {

var minSize = 15; //最小字体

var maxSize = 30; //最大字体

var newOne = 600; //生成雪花间隔

var flakColor = "#1bd3ff"; //雪花颜色

var flak = $("

position: "absolute",

"top": "0px"

}).html("❉"); //定义一个雪花

var dhight = $(window).height(); //定义视图高度

var dw = $(window).width() - 80; //定义视图宽度

setInterval(function () {

var sizeflak = minSize + Math.random() * maxSize; //产生大小不等的雪花

var startLeft = Math.random() * dw; //雪花生成是随机的left值

var startOpacity = 0.7 + Math.random() * 0.3; //随机透明度

var endTop = dhight - 100; //雪花停止top的位置

var endLeft = Math.random() * dw; //雪花停止的left位置

var durationfull = 5000 + Math.random() * 3000; //雪花飘落速度不同

flak.clone().appendTo($("body")).css({

"left": startLeft,

"opacity": startOpacity,

"font-size": sizeflak,

"color": flakColor

}).animate({

"top": endTop,

"left": endLeft,

"apacity": 0.1

}, durationfull, function () {

$(this).remove()

});

}, newOne);

}

// 生成雪花 js代码

');

');

geekswg


geekswg生死看淡,不服就干!


欢迎来到我的主页!

     

Copyright © 2020 geekswg All Rights Reserved.

//鼠标特效

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();//调用

一键复制

编辑

Web IDE

原始数据

按行查看

历史

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值