line-intersect+svg实现简单DOM光线投射鼠标跟随交互效果代码
代码语言:html
所属分类:其他
代码描述:line-intersect+svg实现简单DOM光线投射鼠标跟随交互效果代码
代码标签: line-intersect svg 简单 DOM 光线 投射 鼠标 跟随 交互
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en" > <head> <meta charset="UTF-8"> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { background: #13141b; } main section { width: 100vw; height: 100vh; display: grid; grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(2, 1fr); grid-gap: 10vmin; padding: 10vmin; } main section div { width: 100%; height: 100%; background: #252837; } svg { position: fixed; width: 100vw; height: 100vh; top: 0; left: 0; } </style> </head> <body translate="no"> <main> <section> <div data-observe="true"></div> <div data-observe="true"></div> <div data-observe="true"></div> <div data-observe="true"></div> <div data-observe="true"></div> <div data-observe="true"></div> </section> </main> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/svg.3.1.1.js"></script> <script type="module"> import { checkIntersection } from "//repo.bfw.wiki/bfwrepo/js/module/line-intersect/line-intersect.mjs"; const svg = SVG().addTo("body"); function degToRadians(degrees) { return degrees * (Math.PI / 180); } class Raycaster { constructor({ segments }) { this.uniquePoints = []; this.setSegments(segments); } setSegments(segments) { const uniquePoints = segments.reduce((arr, curr) => { for (const point of Object.values(curr)) { if (!arr.some((p) => p.x === point.x && p.y === point.y)) { arr.push(curr.a, curr.b); } } return arr; }, []); const intersections = segments.reduce((acc, curr) => { for (const segment of segments) { const intersection = checkIntersection( curr.a.x, curr.a.y, curr.b.x, curr.b.y.........完整代码请登录后点击上方下载按钮下载查看
网友评论0