JQuery 的 .slideUp()在 .append() 之后不起作用用于将 textarea 的值附加到 div。
HTML:
<html>
<body>
<div id="cont">
<textarea id="txt"></textarea>
<button onclick="click()">Click</button>
</div>
</body>
</html>
JavaScript:
function click(){
var txt = $('#txt').val();
var html = document.createElement('div');
$(html).hide().html(txt);
$('#cont').append(html);
$(html).slideUp(500);
}
我不知道问题出在哪里,因为当我使用 .show() 而不是 .slideUp() 时它工作正常。
最佳答案
好吧...slideDown 让元素显示,slideUp 让它隐藏。尝试
$(html).slideDown(500)
@Philip Hardyhis 说:解决了我的问题。但是,有没有办法让它从底部向上滑动而不必使用 .animate()
我不这么认为,但我认为这很容易: 只需在 html 中放置一个 div 元素(使用 $(html) 将很难处理)让我们称之为“myDiv”并将 html 的所有内容放入 myDiv
然后把div移到窗口外面做动画(注意移到底部外面需要暂时禁用窗口滚动)
$(document).css('overflow','hidden');
$("#myDiv").css({'top':$(document).height(), 'opacity':'0'});
/*outside of the window and transparent*/
$("#myDiv").animate({
'opacity':'1',
'top':'0'
},2000, function(){$(document).css('overflow','auto');});
我觉得应该是这样的
关于javascript - .slideDown() 似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10694420/