// 鼠标移动出现雪花.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实现的更多相关文章

  1. 鼠标选择文字事件js代码,增加层问题

    在页面中增加一个js代码,当用户用鼠标选择文字(鼠标拖动涂蓝文字)时,会出现一个层,提示与这个选择文字有个的信息<script type="text/javascript"& ...

  2. HTML鼠标悬浮显示隐藏 JS方法

    CSS样式表: @charset "utf-8"; /* CSS Document */ .a { width:80px; height:40px; top:200px; left ...

  3. js鼠标右键操作

    一个页面中,BODY中用oncontextmenu='return false'来取消鼠标右键: 在JS中设置oncontextmenu='return true'用window.document. ...

  4. JS实现鼠标移入水波效果

    前言 最近比较沉迷JS,所以我现在来做个鼠标的交互效果 HTML <div style="border-radius;position:relative;width:800px;hei ...

  5. Ext JS - 问答

    Ext JS - 问答 在下面你将可以找到关于Ext JS 的最常见问题的答复.如果没有找到您所需的答复,请访问 Ext JS 论坛或者提交一个支持申请. 如果你确信你的问题可以对本页有补充,请让我们 ...

  6. KRPano资源分析工具使用说明(KRPano XML/JS解密 切片图批量下载 球面图还原 加密混淆JS还原美化)

    软件交流群:571171251(软件免费版本在群内提供) krpano技术交流群:551278936(软件免费版本在群内提供) 最新博客地址:blog.turenlong.com 限时下载地址:htt ...

  7. [JS,NodeJs]个人网站效果代码集合

    上次发的个人网站效果代码集合: 代码集合: 1.彩色文字墙[鼠标涟漪痕迹] 2.彩色旋转圆环 [模仿http://www.moma.org/interactives/exhibitions/2012/ ...

  8. 【工具相关】web-HTML/CSS/JS Prettify的使用

    一,打开Sublime Text,代码如下面所示. 二,鼠标右键--->HTML/CSS/JS Prettify--->Prettify Code.代码如图所示,明显的代码变得整齐了.

  9. JS 常用库汇总收集

    本文不定期更新, 用于汇总记录一些看着 ok 的 JS 库. 库名 简介 项目地址 macy.js 仅 4 kb的 原生 流布局插件 http://macyjs.com/ Driver.js 仅 4 ...

  10. js相关禁止

    遇到网页上有精美图片或者精彩文字想保存时,通常大家都是选中目标后按鼠标右键,在弹出菜单中选择“图片另存为”或“复制”来达到我们的目的.但是,目前有许多网页都屏蔽了鼠标右键,那么用js如何实现禁止鼠标右 ...

随机推荐

  1. 【Azure 云服务】Cloud Service Worker Role Workerrole突然停机,查看Events发现 Defrag Error (0x8900002D)

    问题描述 Cloud Service Worker Role Workerrole突然停机,查看Events,发现是错误源为 Defrag. 错误消息: The volume Windows was ...

  2. [manjaro linux] 安装完成之后的配置工作,以及常用软件的安装

    emmm 很久没有更新了,绝对不是丢掉了博客帐号,有时间还是要好好装饰以下博客的... https://zhuanlan.zhihu.com/p/114296129 看到很多过程 sudo pacma ...

  3. k8s部署nacos集群

    首先创建数据库 nacos 执行以下语句 CREATE TABLE `config_info` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'i ...

  4. css 布局整理2022-4

    理解CSS3里的Flex布局用法(转自网上,博客园修改一些方便更易看懂) 简单有法: 几个横排元素在竖直方向上居中 display: flex; flex-direction: row;//横向排列 ...

  5. vue table 里面 slot 的模板复用 slot-scope template v-for

    vue table 里面 slot 的模板复用 slot-scope template v-for 需求 经常在table里面要有自定义列,但是会有相同的自定义列,这个时候又不想写很多一样的templ ...

  6. WPF之命令

    目录 命令系统的基本元素 基本元素之间的关系 小试命令 WPF的命令库 命令参数 命令与Binding的结合 近观命令 ICommand接口与RoutedCommand 自定义Command 定义命令 ...

  7. etcd每个节点都存储了完整的键值对数据集,为什么扩容etcd集群仍可分散存储压力?

    etcd每个节点都存储了完整的键值对数据集,这主要是为了确保数据的一致性和高可用性.在这种设计下,任何一个节点都可以处理读取请求,并在本地提供数据,从而无需跨节点通信.这种冗余的数据存储方式也增加了系 ...

  8. 自己想到的几道Java面试题

    1.在抽象类中能否写main方法,为什么? 2.在接口中能否写main方法,为什么? 3.Java能否使用静态局部变量,为什么? 4.Java类变量,实例变量,局部变量在多线程环境下是否线程安全,为什 ...

  9. 【atcoder abc281_d】动态规划

    import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * @ ...

  10. 建民的JAVA课堂

    import javax.swing.JOptionPane; public class Main { public static void main(String[] args) { String ...