我有一个关于bodymovin & react的问题(或者实际上也是plain/vanilla html&js)。比方说,一个图形/动作设计师给了我一个搜索域打开的动画。Like this one。然后我想把这个动画集成到我的网站上,这样当用户点击搜索栏时,这个动画就会播放。
我该怎么做呢?我只有一个bodymovin JSON或svg文件,可能是gif。我确实知道如何在我的网站上简单地显示这个动画。但我真的不明白底层功能(实际的HTML/JS/CSS搜索栏组件)是如何与动画绑定的?
我将非常感谢这里的一些大体方向。
发布于 2018-08-09 03:36:52
您需要为鼠标事件编写一个侦听器。类似于:
HTML:
<element onmouseover="myScript"> <script> function mouseOver() { <!-- Script goes here--> } function mouseOut() { <!-- Script goes here--> } </script>JS:
函数= object.onmouseover (){myScript};
或
Object.addEventListener(“鼠标悬停”,myScript);
Bodymovin使用JavaScript启动动画,所以只需将动画设置为在搜索栏扩展后停止鼠标悬停或鼠标单击,然后将动画设置为在鼠标移出时向后播放。
另一个例子:来源:https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onmouseover_html
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("p").hover(function(){
$(this).css("background-color", "yellow");
}, function(){
$(this).css("background-color", "white");
});
});
</script>
</head>
<body>
<p>Hover the mouse pointer over this paragraph.</p>
</body>
</html>我希望这篇文章能给你一个做什么的想法,并对你有所帮助!
https://stackoverflow.com/questions/46907912
复制相似问题