【问题标题】:How do I make a div animation slide up and disappear?如何让 div 动画向上滑动并消失?
【发布时间】:2013-11-15 06:33:21
【问题描述】:

我知道这听起来像是一个基本问题,但事实是我不是动画专家,而且很难根据 x 和 y 计算数学。所以,我想知道如何让“gl_banner” div 在 0.5-1 秒后简单地向上滑动并消失,它下面的内容将被推到原来的位置。我使用什么 css 属性? CSS动画?过渡?我该怎么做?

附:我对动画做了一些研究,看到了很多动画,高级动画,但找不到简单的上滑动画。一点帮助表示赞赏!谢谢!

HTML 代码:

<div id="gl_banner" style="display:none; visibility:hidden;">Good Luck! :)</div>
                <form id="quiz" action="grade.php" method="post" style="visibility:hidden;">
                    <!--Question 1-->
                    <h3>1. How many percent of modern camera phones use CMOS?</h3>
                    <div>
                        <input type="radio" name="question-1-answers" id="question-1-answers-A" value="A" />
                        <label for="question-1-answers-A">A) 20%</label>
                        <br/>
                        <input type="radio" name="question-1-answers" id="question-1-answers-B" value="B" />
                        <label for="question-1-answers-B">B) 80%</label>
                        <br/>
                        <input type="radio" name="question-1-answers" id="question-1-answers-C" value="C" />
                        <label for="question-1-answers-C">C) 50%</label>
                        <br/>
                        <input type="radio" name="question-1-answers" id="question-1-answers-D" value="D" />
                        <label for="question-1-answers-D">D) 90%</label>
                    </div>
                    <!--Question 2-->
                    <h3>2. Which type of camera setting(s) is best for greater control and flexibility in terms of focusing on a subject?</h3>
                    <div>
                        <input type="radio" name="question-2-answers" id="question-2-answers-A" value="A" />
                        <label for="question-2-answers-A">A) Manual Focus</label>
                        <br/>
                        <input type="radio" name="question-2-answers" id="question-2-answers-B" value="B" />
                        <label for="question-2-answers-B">B) Auto Focus</label>
                        <br/>
                        <input type="radio" name="question-2-answers" id="question-2-answers-C" value="C" />
                        <label for="question-2-answers-C">C) Both A and B</label>
                        <br/>
                        <input type="radio" name="question-2-answers" id="question-2-answers-D" value="D" />
                        <label for="question-2-answers-D">D) Neither</label>
                    </div>
                    <!--Question 3-->
                    <h3>3. What are the three properties included in an exposure triangle?</h3>
                    <div>
                        <input type="radio" name="question-3-answers" id="question-3-answers-A" value="A" />
                        <label for="question-3-answers-A">A) White Balance, ISO, Low Light</label>
                        <br/>
                        <input type="radio" name="question-3-answers" id="question-3-answers-B" value="B" />
                        <label for="question-3-answers-B">B) Shutter Speed, Exposure, ISO</label>
                        <br/>
                        <input type="radio" name="question-3-answers" id="question-3-answers-C" value="C" />
                        <label for="question-3-answers-C">C) Aperture, ISO, Exposure</label>
                        <br/>
                        <input type="radio" name="question-3-answers" id="question-3-answers-D" value="D" />
                        <label for="question-3-answers-D">D) ISO, Aperture, Shutter Speed</label>
                    </div>
                    <!--Question 4-->
                    <h3>4. The higher the ISO, the more noise it produces in an image.</h3>
                    <div>
                        <input type="radio" name="question-4-answers" id="question-4-answers-A" value="A" />
                        <label for="question-4-answers-A">A) True</label>
                        <br/>
                        <input type="radio" name="question-4-answers" id="question-4-answers-B" value="B" />
                        <label for="question-4-answers-B">B) False</label>
                    </div>
                    <!--Question 5-->
                    <h3>5. What is the name of the smartphone you've seen all over this site?</h3>
                    <div>
                        <input type="radio" name="question-5-answers" id="question-5-answers-A" value="A" />
                        <label for="question-5-answers-A">A) Nokia Pureview 808</label>
                        <br/>
                        <input type="radio" name="question-5-answers" id="question-5-answers-B" value="B" />
                        <label for="question-5-answers-B">B) Nokia Lumia 1020</label>
                        <br/>
                        <input type="radio" name="question-5-answers" id="question-5-answers-C" value="C" />
                        <label for="question-5-answers-C">C) Nokia Lumia 925</label>
                        <br/>
                        <input type="radio" name="question-5-answers" id="question-5-answers-D" value="D" />
                        <label for="question-5-answers-D">D) Nokia Lumia 920</label>
                    </div>
                    <br />
                    <hr style="border-top:1px; border-style:solid; border-color: #000;" />
                    <input style="cursor:pointer;" type="submit" value="Submit Quiz" />
                </form>

JavaScript 代码:

function takeQuiz()
{
// hide the intro
document.getElementById('intro').style.display = 'none';

// display the quiz
document.getElementById('quiz').style.visibility = 'visible';
document.getElementById('gl_banner').style.display = 'block';
document.getElementById('gl_banner').style.visibility = 'visible';
} 

【问题讨论】:

    标签: javascript html css css-transitions css-animations


    【解决方案1】:

    使用 jQuery 库。 例如:

    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    
    $( "intro" ).hide(); //hide div "intro" immd 
    $( "intro" ).click(function( event ) {//hide div "intro" on click 
      event.preventDefault();
      $( this ).hide();
    });
    
    $( "intro" ).show(); //to show after hide
    
    $( "intro" ).fadeOut();
    $( "intro" ).fadeIn();
    

    【讨论】:

    • 我对 jquery 一无所知。我只想要一个不使用库的简单 javascript 代码。
    • 只需在 部分中添加此脚本包含行,并遵循确切的语法。很简单!
    • 只需阅读它,它的作用与我的 javascript 代码完全相同。我现在要更改的是“gl_banner” div 以动画方式向上滑动并消失,就是这样。
    • 使用 $("gl_banner").fadeout();
    • 嗯,我现在无法运行 jquery 代码。我在您的评论后添加了我的以包括我的。对吗?
    【解决方案2】:

    查看我使用来自 JQuery 的 click 函数制作的示例:

    Knee's Fiddle


    玩得开心(:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-06
      • 2014-03-25
      相关资源
      最近更新 更多