鼠标移动出现雪花-js实现
// 鼠标移动出现雪花.html
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://wow.techbrood.com/libs/jquery/jquery-1.11.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
(function snowflakeCursor() { var possibleEmoji = ["️"]
var width = window.innerWidth;
var height = window.innerHeight;
var cursor = {
x: width / 2,
y: width / 2
};
var particles = []; function init() {
bindEvents();
loop();
} // Bind events that are needed
function bindEvents() {
document.addEventListener('mousemove', onMouseMove);
document.addEventListener('touchmove', onTouchMove);
document.addEventListener('touchstart', onTouchMove); window.addEventListener('resize', onWindowResize);
} function onWindowResize(e) {
width = window.innerWidth;
height = window.innerHeight;
} function onTouchMove(e) {
if (e.touches.length > 0) {
for (var i = 0; i < e.touches.length; i++) {
addParticle(e.touches[i].clientX, e.touches[i].clientY, possibleEmoji[Math.floor(Math.random() * possibleEmoji.length)]);
}
}
} function onMouseMove(e) {
cursor.x = e.clientX;
cursor.y = e.clientY; addParticle(cursor.x, cursor.y, possibleEmoji[Math.floor(Math.random() * possibleEmoji.length)]);
} function addParticle(x, y, character) {
var particle = new Particle();
particle.init(x, y, character);
particles.push(particle);
} function updateParticles() { // Updated
for (var i = 0; i < particles.length; i++) {
particles[i].update();
} // Remove dead particles
for (var i = particles.length - 1; i >= 0; i--) {
if (particles[i].lifeSpan < 0) {
particles[i].die();
particles.splice(i, 1);
}
} } function loop() {
requestAnimationFrame(loop);
updateParticles();
} /**
* Particles
*/ function Particle() { this.initialStyles = {
"position": "absolute",
"display": "block",
"pointerEvents": "none",
"z-index": "10000000",
"fontSize": "16px",
"will-change": "transform"
}; // Init, and set properties
this.init = function(x, y, character) { this.velocity = {
x: (Math.random() < 0.5 ? -1 : 1) * (Math.random() / 2),
y: (1 + Math.random())
}; this.lifeSpan = 120 + Math.floor(Math.random() * 60); //ms this.position = {
x: x - 20,
y: y - 20
}; this.element = document.createElement('span');
this.element.innerHTML = character;
applyProperties(this.element, this.initialStyles);
this.update(); document.body.appendChild(this.element);
}; this.update = function() {
this.position.x += this.velocity.x;
this.position.y += this.velocity.y; this.velocity.x += (Math.random() < 0.5 ? -1 : 1) * 2 / 75;
this.velocity.y -= Math.random() / 400; this.lifeSpan--; this.element.style.transform = "translate3d(" + this.position.x + "px," + this.position.y + "px,0) scale(" + (this.lifeSpan / 180) + ") rotate(" + (2 * this.lifeSpan) + "deg)"; } this.die = function() {
this.element.parentNode.removeChild(this.element);
} } /**
* Utils
*/ // Applies css `properties` to an element.
function applyProperties(target, properties) {
for (var key in properties) {
target.style[key] = properties[key];
}
} init();
})();
</script>
</body>
</html>
鼠标移动出现雪花-js实现的更多相关文章
- 鼠标选择文字事件js代码,增加层问题
在页面中增加一个js代码,当用户用鼠标选择文字(鼠标拖动涂蓝文字)时,会出现一个层,提示与这个选择文字有个的信息<script type="text/javascript"& ...
- HTML鼠标悬浮显示隐藏 JS方法
CSS样式表: @charset "utf-8"; /* CSS Document */ .a { width:80px; height:40px; top:200px; left ...
- js鼠标右键操作
一个页面中,BODY中用oncontextmenu='return false'来取消鼠标右键: 在JS中设置oncontextmenu='return true'用window.document. ...
- JS实现鼠标移入水波效果
前言 最近比较沉迷JS,所以我现在来做个鼠标的交互效果 HTML <div style="border-radius;position:relative;width:800px;hei ...
- Ext JS - 问答
Ext JS - 问答 在下面你将可以找到关于Ext JS 的最常见问题的答复.如果没有找到您所需的答复,请访问 Ext JS 论坛或者提交一个支持申请. 如果你确信你的问题可以对本页有补充,请让我们 ...
- KRPano资源分析工具使用说明(KRPano XML/JS解密 切片图批量下载 球面图还原 加密混淆JS还原美化)
软件交流群:571171251(软件免费版本在群内提供) krpano技术交流群:551278936(软件免费版本在群内提供) 最新博客地址:blog.turenlong.com 限时下载地址:htt ...
- [JS,NodeJs]个人网站效果代码集合
上次发的个人网站效果代码集合: 代码集合: 1.彩色文字墙[鼠标涟漪痕迹] 2.彩色旋转圆环 [模仿http://www.moma.org/interactives/exhibitions/2012/ ...
- 【工具相关】web-HTML/CSS/JS Prettify的使用
一,打开Sublime Text,代码如下面所示. 二,鼠标右键--->HTML/CSS/JS Prettify--->Prettify Code.代码如图所示,明显的代码变得整齐了.
- JS 常用库汇总收集
本文不定期更新, 用于汇总记录一些看着 ok 的 JS 库. 库名 简介 项目地址 macy.js 仅 4 kb的 原生 流布局插件 http://macyjs.com/ Driver.js 仅 4 ...
- js相关禁止
遇到网页上有精美图片或者精彩文字想保存时,通常大家都是选中目标后按鼠标右键,在弹出菜单中选择“图片另存为”或“复制”来达到我们的目的.但是,目前有许多网页都屏蔽了鼠标右键,那么用js如何实现禁止鼠标右 ...
随机推荐
- JS笔记:方法两次调用,执行不同分支(公共变量,闭包,类三种方法实现)
好家伙, 当我们对一个方法进行两次调用,我们希望第一次执行A分支,第二次执行B分支,该怎么做? 这意味着在连续的两次调用中,方法的执行逻辑会交替执行不同的分支. 方法一:公共变量 let flag ...
- [Linux] 快速修改hosts访问github
sudo sed -i '/github/d' /etc/hosts sudo bash -c "curl https://gitlab.com/ineo6/hosts/-/raw/mast ...
- python中json.dumps() 与json.dump(),json.load()与json.loads()区别?
json.dumps() 将 Python 对象转换为 JSON 字符串,并返回该字符串.而 json.dump() 将 Python 对象转换为 JSON 字符串,并将该字符串写入文件. json. ...
- 6、zookeeper应用场景-分布式唯一ID
分布式唯一id案例 原理:使用zookeeper有序节点,节点后会加上有序的id,用这个id来当唯一ID 在过去的单库单表型系统中,通常第可以使用数据库字段自带的auto_ increment属性来自 ...
- C1. Good Subarrays (Easy Version)
思路:我们枚举每一个左端点,对于每一个左端点,寻找最长的满足条件的区间,这个区间长度就是左端点对答案的贡献,可以发现具有单调性,右端点只会前进不会倒退.所以我们两个指针各扫一遍区间就可以. #incl ...
- nvm-windows 安装遇到的问题 node目录卸载后(有残留)记得改名
需求 网上好多新项目都需要最新版的node,所有需要切换node版本 nvm-windows https://github.com/coreybutler/nvm-windows 安装步骤-问题 删除 ...
- rancher添加用户报错x509: certificate has expired Internal error occurred: failed calling webhook "rancherauth.cattle.io":
错误信息: Internal error occurred: failed calling webhook "rancherauth.cattle.io": Post https: ...
- Android 获取设备的CPU型号和设备型号
原文: Android 获取设备的CPU型号和设备型号-Stars-One的杂货小窝 之前整的项目的总结信息,可能不太全,凑合着用吧,代码在最下面一节 CPU型号数据 华为: ro.mediatek. ...
- OBS无法捕获 chrome、webkit、electron窗口,捕获后黑屏
使用 electron 打包的 pc 应用,用于直播软件推流的 OBS 捕获窗体黑屏 现象:唯独chrome浏览器 edge 浏览器等,其它窗体都正常. 猜测:是由 chromium 内核引起的 修改 ...
- 各种O总结及阿里代码规范总结
首先梳理下POJO POJO包括 DO/DTO/BO/VO(所有的POJO类属性必须使用包装数据类型.) 定义 DO/DTO/VO 等 POJO 类时,不要设定任何属性默认值. controller使 ...