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);

更多相关文章

  1. Server.Htmlencode用于文本域显示带的html代码
  2. IOS学习之WebView加载本地HTML代码或网络资源
  3. html5 css3 背景视频循环播放代码
  4. HTML5 标签audio添加网页背景音乐代码
  5. 我无法理解为什么我的代码中的单击选择文本
  6. js字符串与html代码互相转换时怪想法:自己解析js字符串成普通字
  7. 如何定义两个日期之间的Kendo网格列过滤器?
  8. 解决FCKEditor编辑器在浏览器返回时显示html源代码的问题
  9. 高分求:如何解析IdHTTP获得的http代码?用mshttp的IHTMLDocument2可

随机推荐

  1. android开发之设置Edittext密码的方法
  2. 【拿来主义】Android反编译工具
  3. Android(安卓)判断Root的方法
  4. Android 线程优先级设置方法
  5. Google手机操作系统Android应用开发入门
  6. Android 数据库简单操作
  7. Android缓存理解
  8. Android(安卓)frameworks中Bn*和Bp*的区
  9. Android系统启动流程 -- android
  10. Android笔记-2