0

我希望在<div id="fadeout">单击提交按钮时淡出,然后<div id="fadein">淡入以替换以前的 div。一点运气都没有。

我已经尝试了几种方法,但就是想不通。

任何帮助表示赞赏

    <html>
    <title>Break Calculator</title>

<head>
<style>
body {
    background: #0e415f;
    min-width:55em;
    max-width:200em;
    font-family: Omnes, Myriad Pro, arial, Helvetica;
    color: #f1a400;}

.salary_div {
    width: 12em;
    margin: 0 auto;}

.salary_input{
    width: 6em;
    height: 1.2em;
    font-size: 2em;}

.submit_div {
    width: 8em; 
    margin: 1em auto;}  

.header {
    width: 55em;
    margin: 0 auto;}

.clock {
    border: .1em solid #f1a400 double;
    border-radius: .1em;
    border-style: double;
    width: 3.5em;
    margin: 20 auto;    

    font-size: 10em;
    text-align:center;}

.money {
    border: .1em solid #f1a400 double;
    border-radius: .1em;
    border-style: double;
    width: 3.5em;
    margin: 20 auto;

    font-size: 10em;
    text-align:center;}

.buttons {
    width: 24.5em; 
    margin: 1em auto;}  

.button_style{
    height:2.5em;
    width:6em;
    font-size:1.2em;
    margin: 0 .3em;
    background: #f1a400;
    border-radius: .4em;
    border: 0;}
</style>


<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript">
var salary;
var seconds=-1.0; /* To start clock at 0 seconds */
var min=0;
var time;
var secPay;
var timerPay = 0; 


function getSalary() {
        var salaryAm = document.getElementById("salaries");
        salary = salaryAm.value;
        secPay = salary/(52*40*60*60); // Weeks * Hours * Minutes * Seconds *// 
        }
function timer(){
        seconds++;       

        if(seconds>59){
                min++;
                document.getElementById("mins").innerHTML=padTimer(min);
                seconds=0;}

        document.getElementById("secs").innerHTML=padTimer(seconds);    
        document.getElementById("money").innerHTML=parseFloat(secPay*timerPay++).toFixed(2);
        };

function padTimer(x) {
    if (x<=9) { x = ("0"+x); }
    return x;}

function start(){
    if (getSalary()) {
        alert("please check input");
    } else {
        time=setInterval(timer, 1000);
        timer();}
  };

function pause() { 
    clearInterval(time);
    seconds--;
    timerPay--;};

function reset(){
    seconds=-1.0;
    timerPay=0;
    time=0;
    if (min !=0){
        min=0;}
    };

</script>
</head>

<body>


    <div class="header"><img src="breakcalc.png"></div>
<div id="fadeout">
    <div class="salary_div">
        <input id="salaries" type="text" class="salary_input">
    </div>

    <div class="submit_div">
        <a id="submit"><button class="button_style">Submit</button></a>
    </div>
</div>

<div id="fadein">
    <div class="clock" id="slideout">
        <span id="mins" >00</span>:<span id="secs">00</span>
    </div>

    <div class="money">
        <span>$ </span><span id="money">0.00</span>
    </div>

    <div class="buttons">
        <a href="#" id="button" onclick="start()" ondblclick="return false;"><button class="button_style">Start</button></a>
        <a href="#" id="button" onclick="pause()"><button class="button_style">Stop</button></a>
        <a href="#" id="button" onclick="reset()"><button class="button_style">Reset</button></a>
    </div>
</div>  
</body>

</html>
4

4 回答 4

1

将此添加到您的脚本标签中:

$(document).ready(function() {
    $("#fadein").hide();
    $("#submit button").click(function() {
        $("#fadeout").fadeOut("slow", function() {
            $("#fadein").fadeIn("slow");
        });
    });
});

JSFiddle 演示

于 2013-09-18T17:15:29.353 回答
0

我更改了您正在使用的 jquery 库 - 之前的库对我没有解决。另外,我添加了对 ready 的调用并删除了嵌套<button> in <a>.

<html>
        <title>Break Calculator</title>
    <head>
    <style>
    body {
        background: #0e415f;
        min-width:55em;
        max-width:200em;
        font-family: Omnes, Myriad Pro, arial, Helvetica;
        color: #f1a400;}

    .salary_div {
        width: 12em;
        margin: 0 auto;}

    .salary_input{
        width: 6em;
        height: 1.2em;
        font-size: 2em;}

    .submit_div {
        width: 8em; 
        margin: 1em auto;}  

    .header {
        width: 55em;
        margin: 0 auto;}

    .clock {
        border: .1em solid #f1a400 double;
        border-radius: .1em;
        border-style: double;
        width: 3.5em;
        margin: 20 auto;    

        font-size: 10em;
        text-align:center;}

    .money {
        border: .1em solid #f1a400 double;
        border-radius: .1em;
        border-style: double;
        width: 3.5em;
        margin: 20 auto;

        font-size: 10em;
        text-align:center;}

    .buttons {
        width: 24.5em; 
        margin: 1em auto;}  

    .button_style{
        height:2.5em;
        width:6em;
        font-size:1.2em;
        margin: 0 .3em;
        background: #f1a400;
        border-radius: .4em;
        border: 0;}
    </style>


    <script src="http://codeorigin.jquery.com/jquery-1.10.2.min.js"></script>
    <script type="text/javascript">
    var salary;
    var seconds=-1.0; /* To start clock at 0 seconds */
    var min=0;
    var time;
    var secPay;
    var timerPay = 0; 


    function getSalary() {
            var salaryAm = document.getElementById("salaries");
            salary = salaryAm.value;
            secPay = salary/(52*40*60*60); // Weeks * Hours * Minutes * Seconds *// 
            }
    function timer(){
            seconds++;       

            if(seconds>59){
                    min++;
                    document.getElementById("mins").innerHTML=padTimer(min);
                    seconds=0;}

            document.getElementById("secs").innerHTML=padTimer(seconds);    
            document.getElementById("money").innerHTML=parseFloat(secPay*timerPay++).toFixed(2);
            };

    function padTimer(x) {
        if (x<=9) { x = ("0"+x); }
        return x;}

    function start(){
        if (getSalary()) {
            alert("please check input");
        } else {
            time=setInterval(timer, 1000);
            timer();}
      };

    function pause() { 
        clearInterval(time);
        seconds--;
        timerPay--;};

    function reset(){
        seconds=-1.0;
        timerPay=0;
        time=0;
        if (min !=0){
            min=0;}
        };

        $(document).ready(function()
        {
        $("#fadein").hide();
            $("#submit").click(function()
            {
                $("#fadeout").hide(300);
                $("#fadein").show(300);
            });
        });
    </script>
    </head>

    <body>


        <div class="header"><img src="breakcalc.png"></div>
    <div id="fadeout">
        <div class="salary_div">
            <input id="salaries" type="text" class="salary_input">
        </div>

        <div class="submit_div">
            <button id="submit" class="button_style">Submit</button>
        </div>
    </div>

    <div id="fadein">
        <div class="clock" id="slideout">
            <span id="mins" >00</span>:<span id="secs">00</span>
        </div>

        <div class="money">
            <span>$ </span><span id="money">0.00</span>
        </div>

        <div class="buttons">
            <a href="#" id="button" onclick="start()" ondblclick="return false;"><button class="button_style">Start</button></a>
            <a href="#" id="button" onclick="pause()"><button class="button_style">Stop</button></a>
            <a href="#" id="button" onclick="reset()"><button class="button_style">Reset</button></a>
        </div>
    </div>  
    </body>

    </html>
于 2013-09-18T17:13:13.227 回答
0

放置

$(document).on("click", ".submit_div", function() {
    $("#fadeout").fadeOut('slow', function() {
        $("#fadein").fadeIn('slow');
    });
});

在你的脚本中,应该做到这一点。

于 2013-09-18T17:13:49.590 回答
0

您可以使用jQuery 的fadeIn 和fadeOut 函数使这项任务更容易。见http://jsfiddle.net/BpnVQ/2/

$(document).ready(function() {
    $('button').click(function() {
        $("#one").fadeOut('slow', function() {
            $("#two").fadeIn('slow');
        });
    });
});
于 2013-09-18T17:11:17.117 回答