2012-04-25 100 views
0

我正在设计一个静态HTML页面。它有两个输入栏和一个更改按钮。移动文本框动画

<form name="formTextBox" method="post"> 

    <span id="departImage"> 
     <img src="images/FlightImg.png"> 
    </span> 

    <span class="spanInputOne" id="spanInputOneId"> 
     <input type="text" maxlength="5" 
      class="textBox" id="departTextBox" name="txtDpt" /> 
    </span> 

    <input type="image" src="images/SwitchMode.png" 
     class="centerButton" id="changeButton" 
     onclick="change()" value="change" /> 

    <span id="arrveImage"> 
     <img src="images/FlightImgDown.png"> 
    </span> 

    <span class="spanInputTwo" id="spanInputTwoId"> 
     <input type="text" maxlength="5" 
      class="textBox" id="arrivalTextBox" name="txtArr"/> 
    </span> 

</form> 

我想要做的是,当点击更改按钮时,文本框中的值应该交换平均值,而文本框应该可视地移动到另一个框位置。所以我已经包括CSS3动画的JavaScript如下

CSS3

.animation { 
    position: relative; 
    animation: swap .5s; 
    -moz-animation:swap .5s; /* Firefox */ 
    -webkit-animation:swap 1s; /* Safari and Chrome */ 
} 


@-moz-keyframes swap /* Firefox */ 
{ 
    0% {left:0%; top:0%;} 
    100% {left:50%; top:0%;} 
} 

@-webkit-keyframes swap /* Chrome and Safari */ 
{ 
    0% {left:0%; top:0%;} 
    100% {left:50%; top:0%;} 
} 


.animationOne { 
    position: relative; 
    animation: swapOne .5s; 
    -moz-animation:swapOne .5s; /* Firefox */ 
    -webkit-animation:swapOne .5s; /* Safari and Chrome */ 
} 

@-moz-keyframes swapOne /* Firefox */ 
{ 
    0% {right:0%; top:0%;} 
    100% {right:48%; top:0%;} 
} 

@-webkit-keyframes swapOne /* Chrome and Safari */ 
{ 
    0% {right:0%; top:0%;} 
    100% {right:48%; top:0%;} 
} 

的Javascript

function change() { 

    var depart=document.getElementById("departTextBox").value; 
    var arrive=document.getElementById("arrivalTextBox").value; 

    $("span:eq(1)").addClass("animation"); 
    $("span:eq(3)").addClass("animationOne"); 

    document.formTextBox.txtDpt.value = arrive; 
    document.formTextBox.txtArr.value = depart; 
} 

的文本框设置动画以及预期。但是动画完成后,文本框的值就会消失。能有人帮我...

+1

为那个创建了一个[fiddle](http://jsfiddle.net/6Ln8Z/)...对我来说它在Chrome中工作...你是否在不同的浏览器中检查过它?还有其他什么可以对价值做些什么吗? – 2012-04-25 13:19:16

回答

0

的问题与上述项目与<form>, <input type="img">

由于文本框,图像按钮<input type="image" src="images/SwitchMode.png">是在包括相关的,它张贴的值。因此页面刷新,数据不可用。

我用下面的代码而不是<input type="image" src="images/SwitchMode.png">它工作。

<img src="images/SwitchMode.png" alt="Change" 
    class="centerButton" id="changeButton" 
    onclick="change()" value="change" />