2015-10-19 2 views
8

पर लॉगिन फ़ॉर्म को कैसे हिलाएं मेरे पास HTML और CSS के साथ एक लॉगिन पृष्ठ है। यह पूरी तरह कार्यात्मक है और वह सब कुछ है। हालांकि, जब लॉगिन विफल रहता है तो मैं लॉगिन फॉर्म को हिला देना चाहता हूं। मैं इसे कैसे हिला सकता हूँ। अभी, यह कुछ भी नहीं करता है।त्रुटि

यहां मेरा HTML/CSS/जावास्क्रिप्ट है। यदि अधिक कोड की आवश्यकता है, तो कृपया मुझे बताएं।

एचटीएमएल

<div class="input"> 
    <c:if test="${not empty error}"> 
     <div class="error">${error}</div> 
    </c:if> 
    <c:if test="${not empty msg}"> 
     <div class="msg">${msg}</div> 
    </c:if> 
    <div class="email"> 
     <input type="text" name="username" 
      placeholder="[email protected]"></input> 
    </div> 
    <div class="password"> 
     <input type="password" name="password" placeholder="*********"></input> 
    </div> 
</div> 

<input class="login_btn" type="submit" name="submit" value=""> 

सीएसएस

.container .login_component .login_wrap .login_wp .input input { 
    width: 290px; 
    height: 50px; 
    padding-left: 20px; 
    font-size: 15px; 
    border: none; 
    background: transparent; 
} 

.container .login_component .login_wrap .login_wp .input .email { 
    height: 53px; 
    margin-top: 20px; 
    background: 
     url("http://xiilab.mynetgear.com:81/c.hwang/rems/images/login/input.png"); 
    background-repeat: no-repeat; 
    background-position: center center; 
} 

.container .login_component .login_wrap .login_wp .input .password { 
    height: 53px; 
    margin-top: 20px; 
    background: 
     url("http://xiilab.mynetgear.com:81/c.hwang/rems/images/login/input.png"); 
    background-repeat: no-repeat; 
    background-position: center center; 
} 

.container .login_component .login_wrap .login_wp .login_btn { 
    height: 55px; 
    margin-top: 30px; 
    background: 
     url("http://xiilab.mynetgear.com:81/c.hwang/rems/images/login/login_btn.png"); 
    background-repeat: no-repeat; 
    background-position: center center; 
    border: none; 
    width: 310px; 
} 

जावास्क्रिप्ट

$('input[type=submit]').on('click', function(e){ 
     e.preventDefault(); 
     $('.input').addClass('ahashakeheartache'); 
}); 

$('.input').on('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(e){ 
     $('.input').delay(200).removeClass('ahashakeheartache'); 
}); 
+0

यह आसान लोगों का जवाब देने के लिए हो सकता है पहले कोड का एक बड़ा टुकड़ा करने के लिए खुदाई करने के लिए बिना। यदि * वास्तविक * कोड की वास्तव में आवश्यकता नहीं है, तो यह एक बहुत ही सरल उदाहरण देना या कोड को पूरी तरह से छोड़ना बेहतर हो सकता है। :) – JakeTheSnake

उत्तर

6

Jquery में सरल एनीमेशन का प्रयोग करें jQuery यूआई शामिल

<script src="//code.jquery.com/jquery-1.10.2.js"></script> 
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 

    $(document).on('click', '#yoursubmitdiv', function(){ 

    //code if login fails 

     $("#yourloginfield").effect("shake"); // this will shake your div 



    }); 
+1

गैर-jQuery प्रश्नों के jQuery उत्तर पोस्ट न करें। –

+0

@ जोशियाहेलर बकवास। दिए गए जावास्क्रिप्ट नमूना को देखो। स्पष्ट रूप से JQuery। ऐसा नहीं है कि यह जवाब गलत है; सवाल अनुचित रूप से टैग किया गया है। –

+0

@ दो-बिट एल्केमिस्ट आप सही हैं। मैं अपनी आलोचना में संशोधन करूंगा "वेनिला jQuery प्रश्नों के लिए jQuery यूआई उत्तरों पोस्ट न करें।" –

9

यदि आप animate.css का उपयोग करते हैं तो आप उस प्रभाव को बना सकते हैं। यहां github प्रोजेक्ट है जहां आप स्रोत कोड डाउनलोड कर सकते हैं। ऐसे अन्य प्रभाव भी हैं जिन्हें आप भी देख सकते हैं। animate.css से मिलाते हुए के लिए

कोड:

.animated { 
    -webkit-animation-duration: 1s; 
    animation-duration: 1s; 
    -webkit-animation-fill-mode: both; 
    animation-fill-mode: both; 
} 

.animated.infinite { 
    -webkit-animation-iteration-count: infinite; 
    animation-iteration-count: infinite; 
} 

.animated.hinge { 
    -webkit-animation-duration: 2s; 
    animation-duration: 2s; 
} 

.animated.bounceIn, 
.animated.bounceOut { 
    -webkit-animation-duration: .75s; 
    animation-duration: .75s; 
} 

.animated.flipOutX, 
.animated.flipOutY { 
    -webkit-animation-duration: .75s; 
    animation-duration: .75s; 
} 

@-webkit-keyframes shake { 
    from, to { 
    -webkit-transform: translate3d(0, 0, 0); 
    transform: translate3d(0, 0, 0); 
    } 

    10%, 30%, 50%, 70%, 90% { 
    -webkit-transform: translate3d(-10px, 0, 0); 
    transform: translate3d(-10px, 0, 0); 
    } 

    20%, 40%, 60%, 80% { 
    -webkit-transform: translate3d(10px, 0, 0); 
    transform: translate3d(10px, 0, 0); 
    } 
} 

@keyframes shake { 
    from, to { 
    -webkit-transform: translate3d(0, 0, 0); 
    transform: translate3d(0, 0, 0); 
    } 

    10%, 30%, 50%, 70%, 90% { 
    -webkit-transform: translate3d(-10px, 0, 0); 
    transform: translate3d(-10px, 0, 0); 
    } 

    20%, 40%, 60%, 80% { 
    -webkit-transform: translate3d(10px, 0, 0); 
    transform: translate3d(10px, 0, 0); 
    } 
} 

.shake { 
    -webkit-animation-name: shake; 
    animation-name: shake; 
} 

जे एस

$(document).ready(function(){ 
    $('.submit').click(function(e){ 
     // Code to check login 
     // If fail 
     $('.input').addClass('animated shake'); 
    }); 
}) 
+0

प्रश्न का उत्तर देता हूं क्षमा करें, मैं जावा देव हूं इसलिए मुझे HTML के बारे में बहुत कुछ पता नहीं है। क्या आप इस कोड का उपयोग करने और इसे मेरे अंदर लागू करने में मेरी मदद कर सकते हैं? – bmarkham

+0

@bmarkham आपके सीएसएस में आपको animate.css जोड़ना होगा और फिर कक्षा को एनिमेटेड और हिलाएं। जब आप जांचते हैं कि पासवर्ड सही है या गलत है तो आप एनिमेटेड सीएसएस से कक्षा शेक या अन्य कक्षाएं जोड़ सकते हैं। संपादित उत्तर –

+0

उपरोक्त animate.css से हिलाने के लिए कोड कॉपी करें, और उस श्रेणी में "शेक" श्रेणी जोड़ें जिसमें लॉग इन विफल होने पर आपका लॉगिन होता है – diegorp

3

मैं वास्तव में, यहाँ सादे जावास्क्रिप्ट का उपयोग करने की सलाह देते इसे सरल रखें, लेकिन एक ही पर भी आसान नहीं होता। न केवल shake, और कोड की 50 लाइनें नहीं। कृपया पूछें कि कोड के साथ कुछ अस्पष्ट है, इसे यथासंभव कॉम्पैक्ट रखने की कोशिश की।

var box1Left1 = 100, box1Left2, keepShaking = true; 
 
var originalLeftPos = parseInt(document.getElementById("box1").style.left); 
 
    
 
setTimeout(stopShake, 1000); //Shake for how long 
 
function stopShake() { keepShaking = false; } 
 
    
 
setInterval(shake, 10); //Set shorter interval for faster shake 
 
function shake() { 
 
    if (keepShaking == true) { 
 
    if (box1Left1 < originalLeftPos + 5) { // "+5" = The shake distance. Go right. 
 
     box1Left1++; 
 
     document.getElementById("box1").style.left = box1Left1 + "px"; 
 
     box1Left2 = box1Left1; 
 
    } 
 
    if (box1Left1 >= (originalLeftPos + 5)) { // Go left. 
 
     box1Left2--; 
 
     document.getElementById("box1").style.left = box1Left2 + "px"; 
 
    } 
 
    if(box1Left2 == originalLeftPos) { box1Left1 = box1Left2; } // Go Right Again 
 
    } 
 
}
<div id="box1" style="position:absolute; top: 10px; left: 100px; width: 100px; height: 50px; background-color: #aa39fc;"> 
 
    Incorrect Password 
 
</div>

+0

मुझे यकीन है कि अगर मैं लॉगिन बटन पर क्लिक करता हूं तो यह कोड हिलाता है। – bmarkham

+0

@bmarkham यह नहीं होगा, यह सिर्फ एक उदाहरण है। यदि आप कॉपी और पेस्ट करने के लिए कुछ ढूंढ रहे थे तो मुझे लगता है कि आपके यहां आने वाली सहायता पर थोड़ा विकृत दृष्टिकोण है। – JakeTheSnake

+0

नहीं, मैं सिर्फ मदद की तलाश में हूं जो मेरी सभी समस्याओं पर लागू हो सकता है, सिर्फ एक ही नहीं। – bmarkham

संबंधित मुद्दे