In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article will explain in detail how to use JavaScript to achieve slider verification function. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.
The details are as follows
Document * {margin: 0; padding: 0;} .box {position: relative; width: 500px; height: 40px; border: 1px solid # 000;} p {position: relative; z-index: 5 Font: 20px/40px 'ccc; box-sizing'; text-align: center; color: rgba (95, 90, 90, 0.479);} .btn {width: 40px; height: 40px; border: 1px solid # ccc; box-sizing: border-box; background-color: # fff Cursor: pointer; z-index: 6; position: absolute; top: 0; left: 0; background-position: center; background-repeat: no-repeat; background-size: 50% auto; background-image: url (. / figure 1.png) } .bg {height: 100%; position: absolute; top: 0; left: 0; background-color: # 7ac23c;}
Drag the slider to verify
/ / get the event var box = document.querySelector ('.box') var p = document.querySelector ('p') var btn = document.querySelector ('.btn') var bg = document.querySelector ('.bg') / / the event this.box.onselectstart = function () {return false / / prevent default behavior} / / does not validate successfully by default var flag = false / / Press event btn.onmousedown = function () {var E1 = window.event; var x1 = e1.offsetX; / / move event btn.onmousemove = function () {var e2 = window.event Var x2 = e2.clientX / / calculate the value of left var left = x2-x1 if (left > 0) {/ / set the distance of the slider this.style.left = left + 'px'; / / set the width of the background bg.style.width = left +' px' If (left > box.offsetWidth-this.offsetWidth) {/ / verify success flag = true; p.innerText = 'pass verification' p.style.color ='# 000' / / event clear this.onmousedown = null This.onmousemove = null;} / / Mouse release btn.onmouseup = function () {/ / event clear this.onmousemove = null / / determine whether the verification is successful if (flag) {return} this.style.left = 0; / / set the distance of the slider bg.style.width = 0; / / set the width of the background};}
On "how to use JavaScript to achieve slider verification function" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, please share it out for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.