2016-01-22 85 views
1

好的,下面的代碼的目標是讓左上角向下滑動並使右下側向上滑動。Jquery滑動問題

$(document).ready(function() { 
 
    $("#slider").click(function() { 
 
    /*LEFT-SIDE*/ 
 
    $("#top-left").slideDown(2000); 
 
    $("#main-left").slideUp(7000); 
 
    /*RIGHT SIDE*/ 
 
    $("#main-right").slideDown(2000); 
 
    $("#bottom-right").slideUp(2000); 
 
    }); 
 
});
body { 
 
    background-color: gray; 
 
    margin: 0px; 
 
    margin-top: -15px; 
 
    /*This can and should be ignored it is only for better viewing in the Stack Overflow code snippet*/ 
 
} 
 
#top-left { 
 
    display: none; 
 
    float: left; 
 
    width: 50%; 
 
    background-color: green; 
 
    padding-bottom: 100%; 
 
    z-index: 1000; 
 
} 
 
#bottom-right { 
 
    display: none; 
 
    background-color: gray; 
 
    padding-bottom: 100%; 
 
    z-index: 1000; 
 
} 
 
#main-left { 
 
    padding-top: 50px; 
 
    position: fixed; 
 
    width: 50%; 
 
    height: 100%; 
 
    background-color: blue; 
 
    z-index: -10; 
 
} 
 
#main-right { 
 
    float: right; 
 
    background-color: red; 
 
    width: 50%; 
 
    padding-bottom: 100%; 
 
    z-index: -10; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<section id="complete-left-side"> 
 
    <section id="top-left"> 
 
    <p>Hidden Content</p> 
 
    </section> 
 

 
    <section id="main-left"> 
 
    <p>Main Content</p> 
 
    <button id="slider">Press Me!</button> 
 
    </section> 
 

 
</section> 
 
<section id="complete-right-side"> 
 
    <section id="bottom-right"> 
 
    <p>More hidden Content</p> 
 
    </section> 
 

 
    <section id="main-right"> 
 
    <p>Side Content</p> 
 
    </section> 
 
</section>

的問題是,無論何時按下按鈕按預期右下部不向上滑動。

預先感謝您對誰在這個問題:)

回答

1

你應該按照以下方式在Jquery中進行更改。因爲slideUp會隱藏div,而你試圖顯示div。

並申請CSS來float: right; width: 50%;#bottom-right

<section id="main-right"> 
    <p>Side Content</p> 
    </section> 
    <section id="bottom-right"> 
    <p>More hidden Content</p> 
    </section> 

而且還從主DIV的底部更改序列如上因爲右下角DIV幻燈片。

$(document).ready(function() { 
 
    $("#slider").click(function() { 
 
    /*LEFT-SIDE*/ 
 
    $("#top-left").slideDown(2000); 
 
    $("#main-left").slideUp(7000); 
 
    /*RIGHT SIDE*/ 
 
    $("#main-right").slideUp(2500); //Here 
 
    $("#bottom-right").slideDown(2500); //Here 
 
    }); 
 
});
body { 
 
    background-color: gray; 
 
    margin: 0px; 
 
    margin-top: -15px; 
 
    /*This can and should be ignored it is only for better viewing in the Stack Overflow code snippet*/ 
 
} 
 
#top-left { 
 
    display: none; 
 
    float: left; 
 
    width: 50%; 
 
    background-color: green; 
 
    padding-bottom: 100%; 
 
    z-index: 1000; 
 
} 
 
#bottom-right { 
 
    display: none; 
 
    background-color: gray; 
 
    z-index: 1000; 
 
    float: right; 
 
    width: 50%; 
 
} 
 
#main-left { 
 
    padding-top: 50px; 
 
    position: fixed; 
 
    width: 50%; 
 
    height: 100%; 
 
    background-color: blue; 
 
    z-index: -10; 
 
} 
 
#main-right { 
 
    float: right; 
 
    background-color: red; 
 
    width: 50%; 
 
    padding-bottom: 100%; 
 
    z-index: -10; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<section id="complete-left-side"> 
 
    <section id="top-left"> 
 
    <p>Hidden Content</p> 
 
    </section> 
 

 
    <section id="main-left"> 
 
    <p>Main Content</p> 
 
    <button id="slider">Press Me!</button> 
 
    </section> 
 

 
</section> 
 
<section id="complete-right-side"> 
 
    
 

 
    <section id="main-right"> 
 
    <p>Side Content</p> 
 
    </section> 
 
    <section id="bottom-right"> 
 
    <p>More hidden Content</p> 
 
    </section> 
 
</section>

+1

謝謝凱丹,這將完美的工作! :) – HTMLNoob

1

回答或評論,您需要更改給

的時間間隔像

$(document).ready(function() { 
    $("#slider").click(function() { 
    /*LEFT-SIDE*/ 
    $("#top-left").slideDown(2000); 
    $("#main-left").slideUp(1000); 
    /*RIGHT SIDE*/ 
    $("#main-right").slideDown(2000); 
    $("#bottom-right").slideUp(2000); 
    }); 
}); 

結帳這個Demo

+0

我不澄清抱歉,但我必須#右下角,而不是滑下了。 – HTMLNoob

+0

如果這是你想要的https://jsfiddle.net/xbr1xcxh/5/ –

1

變化你的功能

$(document).ready(function() { 
    $("#slider").click(function() { 
    /*LEFT-SIDE*/ 
    $("#top-left").slideDown(2000); 
    $("#main-left").slideUp(1000); 
    /*RIGHT SIDE*/ 
    $("#main-right").slideUp(2000);// Change Here 
    $("#bottom-right").slideDown(2000);// Change Here 
    }); 
}); 

https://jsfiddle.net/xbr1xcxh/4/

+0

我很抱歉沒有澄清,但我需要#底部右側向上而不是向下滑動。 – HTMLNoob

1

$(document).ready(function() { 
 
    $("#slider").click(function() { 
 
    /*LEFT-SIDE*/ 
 
    $("#top-left").slideDown(2000); 
 
    $("#main-left").slideUp(7000); 
 
    /*RIGHT SIDE*/ 
 
    $("#bottom-right").slideUp(2000); 
 
    $("#main-right").slideUp(2000); 
 
    }); 
 
});
body { 
 
    background-color: gray; 
 
    margin: 0px; 
 
    margin-top: -15px; 
 
    /*This can and should be ignored it is only for better viewing in the Stack Overflow code snippet*/ 
 
} 
 
#top-left { 
 
    display: none; 
 
    float: left; 
 
    width: 50%; 
 
    background-color: green; 
 
    padding-bottom: 100%; 
 
    z-index: 1000; 
 
} 
 
#bottom-right { 
 
    display: none; 
 
    background-color: gray; 
 
    padding-bottom: 100%; 
 
    z-index: 2000; 
 
} 
 
#main-left { 
 
    padding-top: 50px; 
 
    position: fixed; 
 
    width: 50%; 
 
    height: 100%; 
 
    background-color: blue; 
 
    z-index: -10; 
 
} 
 
#main-right { 
 
    float: right; 
 
    background-color: red; 
 
    width: 50%; 
 
    padding-bottom: 100%; 
 
    z-index: -10; 
 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<section id="complete-left-side"> 
 
    <section id="top-left"> 
 
    <p>Hidden Content</p> 
 
    </section> 
 

 
    <section id="main-left"> 
 
    <p>Main Content</p> 
 
    <button id="slider">Press Me!</button> 
 
    </section> 
 

 
</section> 
 
<section id="complete-right-side"> 
 
    <section id="bottom-right"> 
 
    <p>More hidden Content</p> 
 
    </section> 
 

 
    <section id="main-right"> 
 
    <p>Side Content</p> 
 
    </section> 
 
</section>

請檢查。我認爲這是你正在尋找的東西。

+0

我真的很感謝你爲解決我的問題所做的努力。儘管這與我想要的接近,但並不完全準確。由於我不想浪費你的努力,所以我還加上了你的答案。 :) – HTMLNoob