2017-02-04 80 views
0

我需要我的div在點擊時來回轉移,就像只有一個div應該在加載時顯示,另一個應該不可見,點擊時應該可見,反之亦然,任何類型的過渡,我不希望使用光滑的旋轉木馬,不知道我哪裏錯了,不知道爲什麼即使內聯塊不起作用。內容/ div滑塊不工作

function step(n) { 
 
    
 
    if (n == 1) { 
 
    $(".agever").animate({ 
 
     "left": "-300px" 
 
    }, "slow"); 
 
    } else if (n == 2) { 
 
    $(".contever").animate({ 
 
     "right": "300px" 
 
    }, "slow"); 
 
    } 
 
}
.light { 
 
    background: url(images/background.jpg) no-repeat; 
 
    background-size: 100%; 
 
} 
 
img#bg { 
 
    position: fixed; 
 
    top: 0; 
 
    left: 0; 
 
    width: 100%; 
 
    height: 100%; 
 
} 
 
@import url(http://fonts.googleapis.com/css?family=Raleway); 
 
body { 
 
    margin: 0px; 
 
} 
 
.footer { 
 
    float: left; 
 
    background-color: #0f0f0e; 
 
    color: #fff; 
 
    text-align: center; 
 
    padding: 20px 0; 
 
    bottom: 0px; 
 
    top: 125px; 
 
    width: 100%; 
 
    position: relative; 
 
    opacity: .7; 
 
    bottom: 0; 
 
} 
 
.agever { 
 
    position: relative; 
 
    text-align: center; 
 
    background-color: rgba(252, 251, 227, 0.1); 
 
    width: 800px; 
 
    height: 325px; 
 
    border: 2px solid #ffffff; 
 
    margin-left: 100px; 
 
    margin-bottom: 250px; 
 
    top: 150px; 
 
} 
 
.agetitle { 
 
    color: #a88d2e; 
 
    color: rgb(168, 141, 46); 
 
    background-color: #000000; 
 
    background-color: rgba(0, 0, 0, 0); 
 
    font-family: Montserrat; 
 
    font-size: 18px; 
 
    line-height: 28.8px; 
 
    vertical-align: baseline; 
 
    letter-spacing: normal; 
 
    word-spacing: 0px; 
 
    font-weight: bolder; 
 
    font-style: normal; 
 
    font-variant: normal; 
 
    text-transform: none; 
 
    text-decoration: none; 
 
    text-align: center; 
 
    text-indent: 0px; 
 
    padding-top: 40px; 
 
} 
 
.policy, 
 
.policy a { 
 
    text-decoration: none; 
 
    color: #9b9b9b; 
 
    color: rgb(155, 155, 155); 
 
    background-color: #000000; 
 
    background-color: rgba(0, 0, 0, 0); 
 
    font-family (stack): Montserrat; 
 
    font-size: 13px; 
 
    line-height: 28.8px; 
 
    vertical-align: baseline; 
 
    letter-spacing: normal; 
 
    word-spacing: 0px; 
 
    font-weight: bolder; 
 
    font-style: normal; 
 
    font-variant: normal; 
 
    text-transform: none; 
 
    text-decoration: none; 
 
    text-align: center; 
 
    text-indent: 0px; 
 
} 
 
.yes a { 
 
    text-decoration: none; 
 
    font-family: Roboto, sans-serif; 
 
    font-size: 14px; 
 
    line-height: 21px; 
 
    vertical-align: baseline; 
 
    letter-spacing: 0.28px; 
 
    word-spacing: 0px; 
 
    font-style: normal; 
 
    font-variant: normal; 
 
    text-transform: uppercase; 
 
    text-align: center; 
 
    text-indent: 0px; 
 
} 
 
.no a { 
 
    text-decoration: none; 
 
    font-family: Roboto, sans-serif; 
 
    font-size: 14px; 
 
    line-height: 21px; 
 
    vertical-align: baseline; 
 
    letter-spacing: 0.28px; 
 
    word-spacing: 0px; 
 
    font-style: normal; 
 
    font-variant: normal; 
 
    text-transform: uppercase; 
 
    text-align: center; 
 
    text-indent: 0px; 
 
} 
 
.button { 
 
    background-color: #4CAF50; 
 
    border: none; 
 
    color: white; 
 
    padding: 10px 30px; 
 
    text-align: center; 
 
    font-weight: bolder; 
 
    display: inline-block; 
 
    font-size: 16px; 
 
    -webkit-transition-duration: 0.4s; 
 
    transition-duration: 0.4s; 
 
    cursor: pointer; 
 
} 
 
.button1 { 
 
    background-color: #4CAF50; 
 
    border: none; 
 
    color: white; 
 
    padding: 10px 15px; 
 
    text-align: center; 
 
    font-weight: bolder; 
 
    display: inline-block; 
 
    font-size: 16px; 
 
    -webkit-transition-duration: 0.4s; 
 
    transition-duration: 0.4s; 
 
    cursor: pointer; 
 
} 
 
.button5 { 
 
    background-color: #2b2b2b; 
 
    color: #ffffff; 
 
    border: 2px solid #555555; 
 
} 
 
.button5:hover { 
 
    background-color: #555555; 
 
    color: white; 
 
} 
 
.contever { 
 
    position: relative; 
 
    background-color: rgba(252, 251, 227, 0.1); 
 
    width: 950px; 
 
    height: 625px; 
 
    border: 2px solid #ffffff; 
 
    margin-left: 25px; 
 
    margin-bottom: 250px; 
 
    top: 50px; 
 
    overflow-y: scroll; 
 
} 
 
::-webkit-scrollbar { 
 
    width: 18px; 
 
} 
 
::-webkit-scrollbar-track { 
 
    -webkit-box-shadow: inset 0 0 6px rgba(255, 255, 255, 0.3); 
 
    border-radius: 10px; 
 
} 
 
::-webkit-scrollbar-thumb { 
 
    border-radius: 10px; 
 
    -webkit-box-shadow: inset 0 0 6px rgba(255, 255, 255, 0.5); 
 
} 
 
.tandpcontent { 
 
    color: #f6f5d8; 
 
    font-family: Montserrat font-size: 16px text-align: left; 
 
    padding-left: 15px; 
 
    padding-right: 15px; 
 
    line-height: 19.8px 
 
} 
 
.tandptitle { 
 
    color: #a88d2e; 
 
    color: rgb(168, 141, 46); 
 
    background-color: #000000; 
 
    background-color: rgba(0, 0, 0, 0); 
 
    font-family: Montserrat; 
 
    font-size: 30px; 
 
    line-height: 28.8px; 
 
    vertical-align: baseline; 
 
    letter-spacing: normal; 
 
    font-weight: bolder; 
 
    text-decoration: none; 
 
    text-align: center; 
 
    text-indent: 0px; 
 
    padding-top: 40px; 
 
    text-align: center; 
 
} 
 
.close-icon { 
 
    position: relative; 
 
    top: 30px; 
 
    left: 955px; 
 
    display: block; 
 
    box-sizing: border-box; 
 
    width: 40px; 
 
    height: 40px; 
 
    border-width: 6px; 
 
    border-style: solid; 
 
    border-color: gray; 
 
    border-radius: 100%; 
 
    background: -webkit-linear-gradient(-45deg, transparent 0%, transparent 46%, white 46%, white 56%, transparent 56%, transparent 100%), -webkit-linear-gradient(45deg, transparent 0%, transparent 46%, white 46%, white 56%, transparent 56%, transparent 100%); 
 
    background-color: gray; 
 
    box-shadow: 0px 0px 5px 2px rgba(0, 0, 0, 0.5); 
 
    transition: all 0.3s ease; 
 
} 
 
#tandpchange { 
 
    cursor: pointer; 
 
} 
 
#containblockd { 
 
    display: inline-block; 
 
    overflow: hidden; 
 
} 
 
#tandpmaster { 
 
    display: hidden; 
 
    overflow: hidden; 
 
    float: left; 
 
} 
 
agemaster { 
 
    display: inline-block; 
 
    overflow: hidden; 
 
    float: left; 
 
}
<div id="containblockd"> 
 

 
    <div id="agemaster"> 
 
    <div class="agever"> 
 
     <p class="agetitle"> 
 
     YOU MUST BE OF LEGAL DRINKING AGE IN THE COUNTRY IN WHICH YOU ARE ACCESSING THIS SITE 
 
     </p> 
 
     <p class="yes"> 
 
     <a href="main.html"> 
 
      <button class="button button5">YES I AM OF LEGAL DRINKING AGE</button> 
 
     </a> 
 
     </p> 
 
     <p class="no"> 
 
     <a href="https://www.google.co.in/search?site=&source=hp&q=kingspirits.net&oq=kingspirits.net&gs_l=hp.3...518.518.0.1500.2.2.0.0.0.0.155.262.0j2.2.0....0...1c.1.64.hp..0.0.0.0.ZgyZZmdP464"> 
 
      <button class="button1 button5">NO,I AM NOT OF LEGAL DRINKING AGE</button> 
 
     </a> 
 
     </p> 
 
     <p class="policy"> 
 
     By entering this site you agree to our <a title="Law" onclick=" step(1)" id="tandpchange">Terms & Privacy Policy.</a> 
 
     </p> 
 
    </div> 
 
    </div> 
 

 
    <div id="tandpmaster"> 
 
    <a href="#" onclick=" step(2)" class="close-icon"></a> 
 
    <div class="contever"> 
 
     <p class="tandptitle"> 
 
     TERMS & PRIVACY POLICY 
 
     </p> 
 
     <p class="tandpcontent"> 
 
     some content..... 
 
     </p> 
 

 

 
    </div> 
 
    </div>
本身

回答

0

動畫不顯示或隱藏的元素。 所以,你應該添加的功能齊全的隱藏和顯示邏輯,如下所示,通過實例(或使用在顯示和隱藏動畫參數)

function step(n) { 

    if (n == 1) { 
     $(".agever").animate({ 
     "left": "-300px" 
     }, "slow", function(){ 

       $(".agever").hide(); 
       $(".contever").show(); 
     }); 
    } else if (n == 2) { 
    $(".contever").animate({ 
     "right": "300px" 
     }, "slow",function(){ 
       $(".agever").show(); 
       $(".contever").hide(); 
     }); 
    } 
} 

而且你也應該處理後,他們有你的DIV的位置被顯示,隱藏並再次顯示,因爲DIV將在每次動畫後達到的位置返回。