登录滑块验证表单_如何构建双滑块登录和注册表单

登录滑块验证表单Some of you might already know but for those who don’t, I’m starting a Weekly Coding Challenge with all of you! ? 你们中有些人可能已经知道了,但是对于那些不知道的人,我正在与大家一起发起每周编码挑战! ? This challenge is meant to help...
摘要由CSDN通过智能技术生成

登录滑块验证表单

Some of you might already know but for those who don’t, I’m starting a Weekly Coding Challenge with all of you! ?

你们中有些人可能已经知道了,但是对于那些不知道的人,我正在与大家一起发起每周编码挑战! ?

This challenge is meant to help improve our coding skills by practicing on real-life projects.

这项挑战旨在通过在实际项目中进行练习来帮助提高我们的编码技能。

You can read more about this challenge and how you can join it by reading The Complete Guide.

您可以阅读《完整指南》 ,以了解有关此挑战以及如何加入挑战的更多信息。

Alright… so the challenge for this week was: Create a Sign in or Sign up form (or both).

好吧……所以本周的挑战是: 创建一个“登录”或“注册”表单(或同时创建两者)。

Below you can see a demo of what I’ve created:

在下面,您可以查看我创建的演示:

Truth to be told, I’ve struggled a bit with creating the animation ?, but in the end, I managed to make it work. ? I was inspired by this shot on Dribbble by SELECTO — they have some awesome designs, you should check them out!

说实话,我在制作动画方面有些挣扎,但是最后,我设法使它起作用。 ? 我从ibbble博士和SE LECTO的这张照片中得到的启发-他们有一些很棒的设计,您应该检查一下!

项目介绍 (Project description)

Before we move to the actual code, I’d like to break down the things we’re going to have in the component. This will help as it will make the code we write much clearer.

在转到实际代码之前,我想对组件中要包含的内容进行分解。 这将有所帮助,因为它将使我们编写的代码更加清晰。

We have 4 smaller screens/boxes inside the main component (the .container):

我们在主要组件( .container )内部有4个较小的屏幕/框:

  1. The Sign In form

    登录表单

  2. The Sign Up form

    注册表格

  3. The Sign In overlay

    登录覆盖

  4. The Sign Up overlay

    注册覆盖

Also, at one moment in time you can see either:

此外,您会在某一时刻看到以下任一情况:

  • The Sign In form alongside the Sign Up overlay

    签到表格和签到叠加层

  • The Sign Up form alongside the Sign In overlay

    签到表格以及签到覆盖层

In the overlay panels, we have some text and a button. By clicking it you will bring up the other combination of screens and vice-versa. Check the GIF above one more time to see what I mean.

覆盖面板中,我们有一些文本和一个button 。 通过单击它,将显示其他屏幕组合,反之亦然。 再检查一次以上的GIF,看看我的意思。

叠加动画-说明 (The overlay animation — explained)

This is where it might be a little trickier, but I’ll do my best to explain so you can understand the logic behind it.

这可能有点棘手,但是我会尽力解释,以便您了解其背后的逻辑。

We have the following layers for the overlay component:

对于叠加层组件,我们具有以下几层

The overlay-container — this will display the visible area (more on this below) at a certain moment in time. It has a width of 50% of the total container's width.

overlay-container-这将在特定时间显示可见区域(下面有更多信息)。 它的width是容器总width50%

The overlay — this div has a double width size (200%) so it's taking the full width of the main container. (200% * 50%= 100%. The 50% is from the .overlay-container above).

叠加层 -此div的width是其两倍大小( 200% ),因此它占用了主容器的整个宽度。 ( 200% * 50%= 100% 。50%来自上面的.overlay-container )。

The overlay-panels — are the divs which are holding the actual content (the text and the button) we see on the screen. They both have a position of absolute. We can position them wherever we want in the .overlay component. One of the panels is positioned to the left and the other one is positioned to the right. Both having a width of 50% of the .overlay component.

覆盖面板 s是保存我们在屏幕上看到的实际内容(文本和按钮)的div。 他们俩都有absolute

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是一个示例代码,用于验证表单中的图形滑块输入框: ``` <form> <label for="captcha">请拖动图形滑块完成验证:</label> <div id="captcha"></div> <button type="submit">提交</button> </form> <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdn.bootcss.com/jquery-ui-bootstrap/0.5pre/assets/js/jquery-ui-bootstrap.min.js"></script> <link href="https://cdn.bootcss.com/jquery-ui-bootstrap/0.5pre/assets/css/bootstrap.min.css" rel="stylesheet"> <script> const form = document.querySelector('form'); const captcha = document.querySelector('#captcha'); // 初始化滑块 $(captcha).slider({ min: 0, max: 100, value: 0, slide: function(event, ui) { // 滑块滑动时触发 if (ui.value >= 100) { // 如果滑块达到最大值,解锁表单并激活提交按钮 $('#captcha').addClass('text-success').removeClass('text-danger').text('验证通过'); $('#submit').prop('disabled', false); } else { // 如果滑块未达到最大值,锁定表单并禁用提交按钮 $('#captcha').addClass('text-danger').removeClass('text-success').text('请拖动滑块完成验证'); $('#submit').prop('disabled', true); } } }); form.addEventListener('submit', function(event) { event.preventDefault(); // 检查滑块是否已经验证通过 if ($('#captcha').hasClass('text-success')) { // 如果通过验证,提交表单 form.submit(); } else { // 如果未通过验证,弹出提示框 alert('请先完成验证'); } }); </script> ``` 这段代码使用了 jQuery 和 jQuery UI Bootstrap 库来实现图形滑块的功能。在初始化滑块时,我们设置了滑块的最小值、最大值和初始值,并监听了滑块的滑动事件。当滑块滑动时,如果滑块达到了最大值100,则解锁表单并激活提交按钮;否则,锁定表单并禁用提交按钮。 在表单提交时,我们检查滑块是否已经通过验证。如果滑块已经通过验证,则提交表单;否则,弹出提示框。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值