我怎么能用javascript编写这个简短的函数?
16lz
2021-01-22
So I have this code written using jquery, of which is a familiar language for me. However, I have not been able to successfully convert this to a javascript, not using jquery. Any help would be much appreciated!
所以我使用jquery编写了这段代码,对我来说这是一种熟悉的语言。但是,我无法成功将其转换为javascript,而不是使用jquery。任何帮助将非常感激!
// Toggle Function
$('.toggle').click(function(){
// Switches the Icon
$(this).children('i').toggleClass('fa-pencil');
// Switches the forms
$('.form').animate({
height: "toggle",
'padding-top': 'toggle',
'padding-bottom': 'toggle',
opacity: "toggle"
}, "slow");
});
This code switched the icons and forms for my login page.
此代码切换了我的登录页面的图标和表单。
Any tips would be very helpful, thanks for everything!
任何提示都会非常有用,谢谢你的一切!
1 个解决方案
#1
1
Here's a rough conversion into native JavaScript. You'll need to provide the CSS ".show" definition and possibly define some CSS animations there to get whatever animation you want.
这是对原生JavaScript的粗略转换。您需要提供CSS“.show”定义,并可能在那里定义一些CSS动画以获得您想要的任何动画。
const toggleElement = document.querySelector('.toggle');
toggleElement.addEventListener('click', function() {
const icons = this.querySelectorAll('i');
icons.forEach(iconElement => iconElement.classList.toggle('fa-pencil'));
const form = document.querySelector('.form');
form.classList.toggle('show');
}, false);
更多相关文章
- Server.Htmlencode用于文本域显示带的html代码
- IOS学习之WebView加载本地HTML代码或网络资源
- html5 css3 背景视频循环播放代码
- HTML5 标签audio添加网页背景音乐代码
- 我无法理解为什么我的代码中的单击选择文本
- js字符串与html代码互相转换时怪想法:自己解析js字符串成普通字
- 如何定义两个日期之间的Kendo网格列过滤器?
- 解决FCKEditor编辑器在浏览器返回时显示html源代码的问题
- 高分求:如何解析IdHTTP获得的http代码?用mshttp的IHTMLDocument2可