[英]Move image inside div text using hover
I'm trying to imitate this project in jsfiddle and how do I do this hover effect inside my React project
without using jquery
.我正在尝试在 jsfiddle 中模仿这个项目,以及如何在我的
React project
中执行此 hover 效果而不使用jquery
。 Here's my current script tag: <script src="/umi.js"></script>
in index.html
.这是我当前的
script tag: <script src="/umi.js"></script>
in index.html
。 Is there any way to implement this effect without having to include <script>
?有什么方法可以实现这种效果而不必包含
<script>
? Here's my css code:这是我的 css 代码:
.bigTitle{
font-weight: 800;
color: transparent;
font-size:120px;
background: url("https://phandroid.s3.amazonaws.com/wp-content/uploads/2014/05/rainbow-nebula.jpg") repeat;
background-position: 40% 50%;
-webkit-background-clip: text;
position:relative;
text-align:center;
line-height:90px;
letter-spacing: -8px;
}
I would want the image inside the text to react according to my mouse position .我希望文本中的图像根据我的鼠标 position 做出反应。
const windowWidth = window.innerWidth; const windowHeight = window.innerHeight; const mouseMove = (e) => { let mouseX, mouseY; let traX, traY; mouseX = e.pageX; mouseY = e.pageY; traX = ((4 * mouseX) / 570) + 40; traY = ((4 * mouseY) / 570) + 50; document.getElementById('bigTitle').style.backgroundPosition = traX + "%" + traY + "%"; }
#bigTitle{ font-weight: 800; color: transparent; font-size:120px; background: url("https://phandroid.s3.amazonaws.com/wp-content/uploads/2014/05/rainbow-nebula.jpg") repeat; background-position: 40% 50%; -webkit-background-clip: text; position:relative; text-align:center; line-height:90px; letter-spacing: -8px; }
<div id="bigTitle" onmousemove="mouseMove(event)">It works?</div>
This should do it, I just translated whatever it was in the example you provided in javascript.这应该可以,我只是翻译了您在 javascript 中提供的示例中的任何内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.