js实现canvas全息交互视觉效果代码
代码语言:html
所属分类:视觉差异
代码描述:js实现canvas全息交互视觉效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<html lang="en"><head> <meta charset="UTF-8"> <style> * { padding: 0; margin: 0; overflow: hidden; } </style> </head> <body> <!-- This pen is a reverse engineered (and slightly modified) version of the pen by Toshiya Marukubo (@toshiya-marukubo): https://codepen.io/toshiya-marukubo/pen/mdRzyQz I wanted to see how it worked and I figured I'd share :) --> <script> // This is a self-executing function (note the parenthesis at the end that cause it to run). (() => { // This causes the browser to run this code in standards compliant mode rather than "quirks" mode. 'use strict'; // The next three lines create constant (unchangeable) references for a new canvas element, the canvas rendering context, and the diameter value, which determines the size and position of the rectangles that are drawn. const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); const diameter = 15; // These values can't be constants because they need to change whenever the browser is resized or the user moves the mouse. let width = 0; // Width of the viewport let height = 0; // Height of the viewport let halfWidth = 0; // Half the width of the viewport (we're storing this to avoid having to calculate it repeatedly in the loop below). let frame; // This variable holds the reference to the frame from requestAnimationFrame so we can cancel the frame when the user resizes or changes the orientation of the browser window. let time = 0; // This is used to store the current position in the animation timeline. let destination = 1; // This is used to smoothe the animation transition to a new position in the timeline. // This function will be called initially on startup (below) and whenever the user resizes or reorients the browser window. const resize = () => { cancelAni.........完整代码请登录后点击上方下载按钮下载查看
网友评论0