关于为HTML手势解锁(Pattern Lock)添加多图案对应不同页面跳转功能的可行性咨询
Is Multi-Pattern Gesture Lock with Different Redirects Achievable?
Absolutely! This is totally feasible with your existing code. The core adjustment lies in expanding the validation logic to map different gesture patterns (represented by their unique string codes) to specific target URLs, instead of checking against a single fixed pattern.
Here's the Modified Implementation
You only need to update the event handler in your HTML script section—no changes are required to the jquery.gesture.password.js file, as it already correctly generates the string code for the drawn pattern.
<body bgcolor="#1F1F1F" class="center"> <div id="gesturepwd"></div> </body> <script src="jquery-2.1.4.min.js"></script> <script src="/src/jquery.gesture.password.js"></script> <script> $("#gesturepwd").GesturePasswd({ backgroundColor:"Opaque", opacity:0.1, color:"#595959", roundRadii:50, pointRadii:12, space:60, width:480, height:480, lineColor:"#01F3C9", zindex :100 }); $("#gesturepwd").on("hasPasswd",function(e,passwd){ // Step 1: Create a map of gesture patterns to target URLs const patternToUrl = { "321456987": "packages.html", // Replace with your "S" pattern's actual code "123698547": "w-r-page.html", // Replace with your "W" pattern's code "741258963": "w-r-page.html" // Replace with your "R" pattern's code (maps to same page as W) }; let isValidPattern = false; let targetPage = ""; // Step 2: Check if the drawn pattern exists in our map if (patternToUrl.hasOwnProperty(passwd)) { isValidPattern = true; targetPage = patternToUrl[passwd]; } // Step 3: Handle validation result if(isValidPattern){ $("#gesturepwd").trigger("passwdRight"); setTimeout(function(){ window.location.href = targetPage; },500); } else{ $("#gesturepwd").trigger("passwdWrong"); } }); </script>
Key Explanations:
- Pattern Mapping: The
patternToUrlobject acts as a lookup table—each key is the string code generated by your gesture lock for a specific pattern, and the value is the URL you want to redirect to. - How to Get Pattern Codes: To find the code for your "S", "W", or "R" patterns, temporarily add
console.log(passwd)inside thehasPasswdevent handler. Draw the pattern, check your browser's developer console, and copy the printed string to use as a key in the map. - Scalability: This approach makes it easy to add more patterns later—just add new key-value pairs to the
patternToUrlobject without rewriting the validation logic.
内容的提问来源于stack exchange,提问作者Shubham Kandalgaonkar
相关产品推荐
相关产品推荐

