如何将此jQuery函数传输到React函数中?
我的问题是我不知道如何将jQuery代码实现到React应用程序中,
这是转换中的交替端,
我经常在应用程序中使用此代码来为页面添加一点动作,但是我显然可以't在React中使用jQuery,所以我将如何获得相同的功能到React App
html代码
< div class =“ box-wrapper loading”>< div class =“ box”>></div&gt> < div class =“ box-wrapper loading”>< div class =“ box”></div></div>
CSS代码
body { Overflow-X:隐藏; } .box-wrapper { -webkit-transition-turation:600ms; 过渡:600ms; } .box-wrapper.loading:nth-child(奇数){ 变换:转换(100%); } .box-wrapper.loading:nth-child(偶){ 变换:转换(-100%); }
问题:
javascript代码
在 settimeout(function(){ element.ClassList.Remove(“ loading”); },索引 * 600); });
My problem is I don't know how to implement the Jquery code into a react app
This is an alternating side coming in transform
I regularly use this code in my applications to add a little motion to the page, but I obviously can't use Jquery in react so how would I go about getting the same functionality in to a react app
Html Code
<div class="box-wrapper loading"><div class="box"></div></div> <div class="box-wrapper loading"><div class="box"></div></div>
CSS Code
body { overflow-x: hidden; } .box-wrapper { -webkit-transition-duration: 600ms; transition-duration: 600ms; } .box-wrapper.loading:nth-child(odd) { transform: translate(100%); } .box-wrapper.loading:nth-child(even) { transform: translate(-100%); }
Issue:
Javascript Code
$(".box-wrapper").each(function (index, element) { setTimeout(function () { element.classList.remove("loading"); }, index * 600); });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我附上了一个简单的示例,说明如何通过React实现上述功能。
这可以根据您的要求进一步优化 /重构,但这为您提供了如何使用React与JQuery所做的事情实现的基本概念。
我建议您看看 react trese transition transition Groups package package 当您开始考虑改善初始功能时,对React中的过渡的控制。
I have attached a simplistic example of how you can achieve the above functionality via React.
This can be further optimized / refactored based upon your requirement, but this gives you a basic idea of how to accomplish with React what you have been doing with jQuery.
I would suggest you to have a look at React Transition Groups package, to have more granular control over transitions in React, when you start thinking of improving your initial functionality.