您好 jquery 的新手,我试图让用户输入会影响动画的值。(向上或向下移动)这是我到目前为止所拥有的,似乎我无法让它传递值以使其动画化,任何帮助都会很棒。
html
<select id="selectBox">
<option selected="selected" class="selectBox" value="top">Top </option>
<option class="selectBox" value="bottom">Bottom </option>
</select>
<input type="text" id="value" />
<input id="button" name="button" value="Animate" type="button">
<div class="box"style="height:100px; width:300px; padding: 35px; margin:50px auto;
border:30px solid #000;">
javascript/jquery
< script type = "text/javascript" >
$("#button").click(function() {
var boxType = $('#selectBox').val();
var value = $('#value').val();
console.log(boxType + " " + value);
if (boxType == "top") {
$(".box").stop().animate({
marginTop: $('input').val('changed input value');
}, 1000);
}
if (boxType == "bottom") {
console.log("marginBottom")
$(".box").stop().animate({
marginBottom: $('input').val('changed input value');
}, 1000);
}
}); < /script>
here it is on JSFIDDLE