鼠标跟随3d变换效果

代码语言:html

所属分类:视觉差异

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>BFW NEW PAGE</title>
    <script  type="text/javascript" src="http://repo.bfw.wiki/bfwrepo/js/bfwone.js"></script>
    <script type="text/javascript">
        bready(function() {
            document.addEventListener('mousemove', e => {

                const x = e.pageX;
                const y = e.pageY;

                const elm = document.querySelector('.card');
                const coords = elm.getBoundingClientRect();

                const elmX = coords.left + (elm.offsetWidth / 2);
                const elmY = coords.top + (elm.offsetHeight / 2);

                const angleX = (elmY - y) / 25;
                const angleY = (elmX - x) / -25;


                elm.style.transform = `rotateX(${angleX}deg)
                rotateY(${angleY}deg)`;

            })
        });
    </script>
    <style>
   .........完整代码请登录后点击上方下载按钮下载查看

网友评论0