有谁知道如何使这段代码具有 .fadein 属性?最好是.fadein 中速。谢谢!
<script>
function LinkOnClick4(box) {
$('#friendresults').load('conversation.php?id=' + box);
}
</script>
最佳答案
首先隐藏元素,加载其内容,然后使用 load
函数的回调函数将其淡入淡出:
function LinkOnClick4(box) {
//select our element to populate, hide it, load in the new content, then once the new content is loaded, fade it back in
$('#friendresults').hide().load('conversation.php?id=' + box, function () {
$(this).fadeIn(750);
});
}
如果您希望元素在页面中保留其空间(而不是完全消失),那么您可以设置它的不透明度,而不是使用 .hide()
和 .fadeIn()
功能:
function LinkOnClick4(box) {
//select our element to populate, hide it, load in the new content, then once the new content is loaded, fade it back in
$('#friendresults').css({ opacity : 0 }).load('conversation.php?id=' + box, function () {
$(this).fadeTo(1, 750);
});
}
两个代码块之间的区别在于,第一个代码块允许相对定位在 #friendresults
元素周围的元素在隐藏时移动,而第二个代码块则阻止页面移动当 #friendresults
元素隐藏/显示时。
如果您需要更多帮助,请参阅一些文档:
.hide()
:http://api.jquery.com/hide.fadeIn()
:http://api.jquery.com/fadein.fadTo()
:http://api.jquery.com/fadeto.css()
:http://api.jquery.com/css
关于javascript - .fadein 与 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8857184/