我如何为表单提交制作以下动画?
(我想而不是输入它,我会创建一个视觉效果。)
答案 0 :(得分:10)
我使用jsFiddle将
的概念证明放在一起http://jsfiddle.net/kAhXd/1/ (动画现在重置,点击提交按钮)
您需要仔细查看CSS,但需要注意的重要一点是<form>
元素的位置设置为 relative ,并且消息元素的位置已设置到绝对。这是为了确保message元素的位置始终相对于表单元素。
<强> HTML 强>
<form><div id="message"></div>
<input> Label 1<br/><br/>
<input> Label 2<br/><br>
<textarea>Larger text area</textarea><br/><br/>
<textarea>And another</textarea><br/><br/>
<button type="button">Submit</button>
</form>
<强> CSS 强>
form { position:relative; width:500px; }
#message {
position:absolute;
display:none;
height:100px;
width:200px;
border: 1px gray solid;
background-color:lime;
font-size: 1.4em;
line-height:100px;
text-align:center;
left: 150px;
bottom:100px;
border-radius: 5px;
}
<强>的JavaScript 强>
$("button").click(function () {
var msg = $("#message");
msg[0].style.cssText = "";
msg.text("Item saved!");
msg.fadeIn('slow').animate({
"bottom": "3px",
"height": "17px",
"font-size": "1em",
"left": "80px",
"line-height": "17px",
"width": "100px"
});
});
答案 1 :(得分:9)
这是安迪的想法,以水平居中为基础。
HTML:
<form><div id="message"></div>
<input> Label 1<br/><br/>
<input> Label 2<br/><br>
<textarea>Larger text area</textarea><br/><br/>
<textarea>And another</textarea><br/><br/>
<button type="button">Submit</button>
CSS:
form {
position:relative;
width:500px;}
#message {
position:absolute;
display:none;
height:100px;
width:200px;
border: 1px gray solid;
background-color:lime;
font-size: 1.4em;
line-height:100px;
text-align:center;
border-radius: 5px;
bottom: 100px;}
居中功能:
(function($) {
$.fn.extend({
center: function() {
return this.each(function() {
var left = ($(window).width() - $(this).outerWidth()) / 2;
$(this).css({
position: 'absolute',
margin: 0,
left: (left > 0 ? left : 0) + 'px'
});
});
}
});})(jQuery);
呼叫中心:
$("#message").center();
点击功能:
$("button").click(function() {
var msg = $("#message");
msg.text("Item saved!")
msg.hide()
msg.stop(true, true).fadeIn('slow').animate({
"bottom": "4px",
"height": "17px",
"font-size": "1em",
"left": "80px",
"line-height": "17px",
"width": "100px"
}).delay(2000).fadeOut('slow').css({
"height": "100px",
"width": "200px",
"font-size": "1.4em",
"line-height": "100px",
"bottom": "100px"
}).center();});
答案 2 :(得分:0)
我会使用jQuery。以下是我将采取的步骤:
<form>
和<input>
字段。<div id="item_saved">Item Saved!</div>
,默认样式为display:none
。更新:已编辑以提供更多信息,并可直接解决问题。