日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

html动态跟随鼠标效果,使用JS实现气泡跟随鼠标移动的动画效果

發布時間:2025/3/11 javascript 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 html动态跟随鼠标效果,使用JS实现气泡跟随鼠标移动的动画效果 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

氣泡跟隨鼠標移動,并在每次點擊時產生不同的變化

效果如下

簡單的氣泡效果

body{background-color:#000000;margin:0px;overflow:hidden}

var canvas = document.createElement('canvas'),

context = canvas.getContext('2d'),

windowW = window.screen.width ,

windowH = window.screen.height ,

Mx,

My,

paused = true;

suzu = [];

booms = [];

boomks = [];

start();

canvas.onmousemove = function(e) {

var loc = canvasMove(e.clientX, e.clientY);

Mx = loc.x;

My = loc.y

};

canvas.onmousedown = function() {

creatarry(Mx, My);

paused = !paused

};

function creatarry(a, b) {

for (var i = 0; i < 40; ++i) {

booms[i] = {

x: a,

y: b,

gravity: 0.3,

speedX: Math.random() * 20 - 10,

speedY: Math.random() * 15 - 7,

radius: Math.random() * 15,

color: Math.random() * 360,

apc: 0.6

};

boomks.push(booms[i]);

if (boomks.length > 300) {

boomks.shift()

};

console.log(boomks)

}

};

function loop1() {

boomks.forEach(function(circle) {

context.beginPath();

context.arc(circle.x, circle.y, circle.radius, 0, Math.PI * 2, false);

context.fillStyle = 'hsla(' + circle.color + ',100%,60%,' + circle.apc + ')';

context.fill();

movecircles(circle)

})

}

function movecircles(circle) {

circle.x += circle.speedX;

circle.speedY += circle.gravity;

circle.y += circle.speedY;

circle.apc -= 0.008

}

function canvasMove(x, y) {

var bbox = canvas.getBoundingClientRect();

return {

x: x - bbox.left * (canvas.width / bbox.width),

y: y - bbox.top * (canvas.height / bbox.height)

}

};

function start() {

document.body.appendChild(canvas);

canvas.width = windowW;

canvas.height = windowH;

setInterval(fang, 25)

}

function fang() {

context.clearRect(0, 0, canvas.width, canvas.height);

loop1();

loop()

}

function loop() {

var circle = new createCircle(Mx, My);

suzu.push(circle);

for (i = 0; i < suzu.length; i++) {

var ss = suzu[i];

ss.render(context);

ss.update()

}

if (suzu.length > 1000) {

suzu.shift()

}

}

function createCircle(x, y) {

this.x = x;

this.y = y;

this.color = Math.random() * 360;

this.radius = Math.random() * 25;

this.xVel = Math.random() * 5 - 2;

this.apc = 0.6;

this.gravity = 0.07;

this.yVel = Math.random() * 10 - 3;

this.render = function(c) {

c.beginPath();

c.arc(this.x, this.y, this.radius, 0, Math.PI * 2, true);

c.fillStyle = 'hsla(' + this.color + ',100%,60%,' + this.apc + ')';

c.fill()

};

this.update = function() {

if (!paused) {

this.yVel += this.gravity;

this.y += this.yVel

} else {

this.y -= 5

}

this.x += this.xVel;

this.apc -= 0.01;

if (this.radius > 1) {

this.radius -= 0.4

}

}?}

總結

以上所述是小編給大家帶來了使用JS實現氣泡跟隨鼠標移動的動畫效果 ,希望對大家有所幫助!

總結

以上是生活随笔為你收集整理的html动态跟随鼠标效果,使用JS实现气泡跟随鼠标移动的动画效果的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。