2017-10-12 53 views
1

我已經創建,點擊一個div顯示轉換到正文。問題是點擊div顯示,但沒有轉換,第二次點擊過渡工作。轉換不起作用的第一次點擊

我有這樣的代碼:

<ul class="nav navbar-nav navbar-right navSelected" id="topNav"> 
      <li><a href="index.php" class="home"> HOME</a></li> 
      <li><a href="about.php" class="about1"> ABOUT</a></li> 
      <li><a href="services.php" class="service"> SERVICES</a></li> 
      <li><a href="news.php" class="newsNav"> NEWS</a></li> 
      <li><a href="javascript:void(0)" class="contact" id="contact"> CONTACT</a></li> 


     </ul> 

接觸點擊鏈接時,DIV打開,所以我創造了這個過渡:

if($('#contactUs').hasClass('moveNav')=== false){ 
     $('#contactUs').addClass('moveNav'); 
     $('body').css('width', '82vw'); 
     $('body').css('transition', 'all .4s ease-in-out'); 
     $('.navWidth').css('width', '82vw'); 
     $('.navWidth').css('transition', 'all .4s ease-in-out'); 
     $('.topSection .cover2').css('margin-right','100px'); 
     $('.topSection .cover2').css('transition','all .4s ease-in-out'); 
     $('.svgMarqueeDesign').css('margin','22px'); 
     $('.textCover').css('width','50%'); 
     } 

,這是div代碼:

<div id="contactUs" class="contactus"> 
<div class="text-right"><div id="close"></div> 

<div class="contactSvg"> 
     <svg class="menusvg1" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" 
      width="75.325px" height="123.408px" viewBox="0 0 75.325 123.408" enable-background="new 0 0 75.325 123.408" 
      xml:space="preserve"> 

</div> 
    <div class="text-center contactUsTitle"> 
     CONTACT US 
    </div> 


    <div id="contactUsForm"> 

     <div class="row"> 
      <div class=" contactUsInputs"> 

       <form action="#" method="post" id="myForm"> 


        <div class="form-group"> 
         <input type="text" class="form-control inputWidth" name="firstName" id="firstName" 
           placeholder="First Name"> 

        </div> 


        <div class="form-group"> 
         <input type="text" class="form-control inputWidth" id="lastName" name="lastName" placeholder="Last Name"> 
        </div> 


        <div class="form-group"> 
         <input type="email" class="form-control inputWidth" name="email" id="email1" 
           placeholder="E-mail Address"> 
        </div> 


        <div class="form-group"> 
         <select class="form-control selectList required " id="selectList" name="selectList" > 
          <option value="">What is this about?</option> 
          <option value="firstchoice">first Choice</option> 
          <option value="secondchoice">second Choice</option> 
          <option value="thirdchoice">third Choice</option> 
          <option value="fourthchoice">fourth Choice</option> 
         </select> 
        </div> 


        <div class="form-group textArea1"> 
         <textarea class="form-control inputWidth" rows="10" name="about" id="about" placeholder="write your message here"></textarea> 

        </div> 
        <div class="text-right"> 
         <button type="submit" class="btn learnMore send">send</button> 

        </div> 
       </form> 


      </div> 
     </div> 

    </div> 
</div> 

忘記了DIV長碼,但它不是從第一次合作, 只有第二次轉變工作由於IM提前

+0

是轉換代碼初始化onload? – tech2017

+1

您應該在'$(window).load(){}'事件中使用上述所有js代碼,以便它可以在加載 –

回答

0

當你的代碼被觸發時它加載。你必須將它綁定到菜單的點擊https://jsfiddle.net/xj0s3a66/

$(document).ready(function() { 
    $("#contact").click(function() { 
    if ($('#contactUs').hasClass('moveNav') === false) { 
     $('#contactUs').addClass('moveNav'); 
     $('body').css('width', '82vw'); 
     $('body').css('transition', 'all .4s ease-in-out'); 
     $('.navWidth').css('width', '82vw'); 
     $('.navWidth').css('transition', 'all .4s ease-in-out'); 
     $('.topSection .cover2').css('margin-right', '100px'); 
     $('.topSection .cover2').css('transition', 'all .4s ease-in-out'); 
     $('.svgMarqueeDesign').css('margin', '22px'); 
     $('.textCover').css('width', '50%'); 
    } 
    }); 
}); 
相關問題