效果如图所示:

index.js

/*!
* Fairy Dust Cursor.js
* - 90's cursors collection
* -- https://github.com/tholman/90s-cursor-effects
* -- https://codepen.io/tholman/full/jWmZxZ/
*/ (function fairyDustCursor() { var possibleColors = ["#D61C59", "#E7D84B", "#1B8798"]
var width = window.innerWidth;
var height = window.innerHeight;
var cursor = {x: width/, y: width/};
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 > ) {
for( var i = ; i < e.touches.length; i++ ) {
addParticle( e.touches[i].clientX, e.touches[i].clientY, possibleColors[Math.floor(Math.random()*possibleColors.length)]);
}
}
} function onMouseMove(e) {
cursor.x = e.clientX;
cursor.y = e.clientY; addParticle( cursor.x, cursor.y, possibleColors[Math.floor(Math.random()*possibleColors.length)]);
} function addParticle(x, y, color) {
var particle = new Particle();
particle.init(x, y, color);
particles.push(particle);
} function updateParticles() { // Updated
for( var i = ; i < particles.length; i++ ) {
particles[i].update();
} // Remove dead particles
for( var i = particles.length -; i >= ; i-- ) {
if( particles[i].lifeSpan < ) {
particles[i].die();
particles.splice(i, );
}
} } function loop() {
requestAnimationFrame(loop);
updateParticles();
} /**
* Particles
*/ function Particle() { this.character = "*";
this.lifeSpan = ; //ms
this.initialStyles ={
"position": "absolute",
"display": "block",
"pointerEvents": "none",
"z-index": "",
"fontSize": "16px",
"will-change": "transform"
}; // Init, and set properties
this.init = function(x, y, color) { this.velocity = {
x: (Math.random() < 0.5 ? - : ) * (Math.random() / ),
y:
}; this.position = {x: x - , y: y - };
this.initialStyles.color = color; this.element = document.createElement('span');
this.element.innerHTML = this.character;
applyProperties(this.element, this.initialStyles);
this.update(); document.querySelector('body').appendChild(this.element);
}; this.update = function() {
this.position.x += this.velocity.x;
this.position.y += this.velocity.y;
this.lifeSpan--; this.element.style.transform = "translate3d(" + this.position.x + "px," + this.position.y + "px, 0) scale(" + (this.lifeSpan / ) + ")";
} 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();
})();

stackoverflow愚人节彩蛋效果的更多相关文章

  1. Android彩蛋效果,微信彩蛋效果

    根据Android源码修改,具有微信彩蛋效果 主要代码 public static class Board extends FrameLayout { public static final bool ...

  2. 震惊!ConcurrentHashMap里面也有死循环,作者留下的“彩蛋”了解一下?

    JDK BUG 这篇文章,聊一下我最近才知道的一个关于 JDK 8 的 BUG 吧. 首先说一下我是怎么发现这个 BUG 的呢? 大家都知道我对 Dubbo 有一定的关注,前段时间 Dubbo 2.7 ...

  3. 震惊!ConcurrentHashMap里面也有死循环,作者留的“彩蛋”?

    JDK BUG 这篇文章,聊一下我最近才知道的一个关于 JDK 8 的 BUG 吧. 首先说一下我是怎么发现这个 BUG 的呢? 大家都知道我对 Dubbo 有一定的关注,前段时间 Dubbo 2.7 ...

  4. 实现了一个百度首页的彩蛋——CSS3 Animation简介

    在百度搜索中有这样一个彩蛋:搜索“旋转”,“跳跃”,“反转”等词语,会出现相应的动画效果(搜索“反转”后的效果).查看源码可以发现,这些效果正是通过CSS3的animation属性实现的. 实现这个彩 ...

  5. 淘宝首页源码藏美女彩蛋(下)(UED新作2013egg)

    我们已经知道,执行美女会得到"彩蛋",而正是彩蛋做到了taobaoUED展现给大家的神奇的前端魅力.今天我们来看看FP.egg&&FP.egg("%cjo ...

  6. [深入浅出Windows 10]模拟实现微信的彩蛋动画

    9.7 模拟实现微信的彩蛋动画 大家在玩微信的时候有没有发现节日的时候发一些节日问候语句如“情人节快乐”,这时候会出现很多爱心形状从屏幕上面飘落下来,我们这小节就是要模拟实现这样的一种动画效果.可能微 ...

  7. Build 2019 彩蛋

    N久没写过博客了… 最近在玩 APEX 但是手残党表示打到15级了,至今杀敌 4 人… 当快递员是越来越顺手了… 今年巨硬的 Build 大会会在 5 月 6-8 号召开 新发布的 Hololens ...

  8. EFCore Owned Entity Types,彩蛋乎?鸡肋乎?之鸡肋篇

    鸡肋 鸡肋(Chicken ribs),现代汉语词语,出自<三国志·魏书·武帝纪>裴松之注引<九州春秋>曰:"夫鸡肋,弃之如可惜,食之无所得,以比汉中,知王欲还也.& ...

  9. 十三个有彩蛋的Linux命令

    原文链接: https://my.oschina.net/u/4045573/blog/2986313   一键下载安装配置文本全部命令所需环境 sudo apt-get updategit clon ...

随机推荐

  1. 色彩空间-- RGB\HSV

    颜色空间 标签(空格分隔): 计算机视觉 颜色通常用三个独立的属性来描述,三个独立变量综合作用,自然就构成一个空间坐标,这就是颜色空间. RGB和CMY颜色模型都是面向硬件的,而HSV(Hue Sat ...

  2. switch语句以及三种循环语句的总结

    1:switch语句(1)格式:switch(表达式) {case 值1:语句体1;break;case 值2:语句体2;break;...default:语句体n+1;break;} 格式解释说明: ...

  3. ASP.NET Core的Data Protect(数据保护)的学习和应用

    转载请注入出处: https://home.cnblogs.com/u/zhiyong-ITNote/ dotnet core中提供了一个新的身份验证框架Identity,它不同于dot net下的身 ...

  4. 一: WCF的服务端与客户端在通信时有三种模式:请求响应模式、数据报模式和双工通讯模式。

    说一下基本知识,  1.如果想要将当前接口作为wcf服务器,则一定要加上[ServiceContract] 契约 2.要想将方法作为wcf服务方法发布给外部调用,则一定要加上    [Operatio ...

  5. Summary

    PDF 暑假开始准备转移博客,试了几个都不怎么满意(我还去试了下LineBlog 不知道那时候在想什么..),屯着一堆文章,,到时候一起发了 现在暂时转移至WordPress,不过还在完善中,预计.. ...

  6. Jmeter测试http+JSON配置相关

    1.添加HTTP信息头管理器 Content-Type application/json Accept application/json 2.添加http请求(方法.编码.路径.body)

  7. VS Code打造一个完美的Springboot开发环境

    对于使用Springboot环境开发java应用,首选IDE还是IntelliJ IDEA(2018),当前版本已经很流畅了,现在开发用的电脑配置基本都能够很6的跑起来,IDEA用起来真心爽啊,比Ec ...

  8. BZOJ2670 : Almost

    求出前缀和$s[]$,那么区间$[l,r]$的几乎平均数$=\frac{s[r]-s[l-1]}{r-l}$. 若只有一个询问,那么可以维护$(i,s[i-1])$的凸壳,在凸壳上二分点$(i,s[i ...

  9. C++学习笔记45:多态性

    运算符重载 运算符是针对新类型数据的实际需要,对原有运算符进行适当的改造 1.比如使复数类的对象可以使用+运算符实现加法: 2.比如使时钟类的对象可以用++运算符实现时间增加1秒: 注意:可以重载为类 ...

  10. Java 不变模式

    在阎宏博士的<JAVA与模式>一书中开头是这样描述不变(Immutable)模式的:一个对象的状态在对象被创建之后就不再变化,这就是所谓的不变模式. 不变模式的结构 不变模式可增强对象的健 ...