javascript - .fadein 与 javascript

标签 javascript jquery

有谁知道如何使这段代码具有 .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 元素隐藏/显示时。

如果您需要更多帮助,请参阅一些文档:

关于javascript - .fadein 与 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8857184/

相关文章:

jquery获取div中的段落

jquery - 如果由 jQuery 设置,CSS3 2D 转换不适用于 IE9

javascript - 包含数据的 jQuery 空文本区域

javascript - 检测数组中接近且具有相同索引值的数字?

javascript - 如何处理重叠矩形的递归函数

javascript - 每次点击后增加的数字?

javascript - 文档加载后在 JS 函数中渲染 Razor 代码

javascript - RxJS:可观察对象和单个观察者的递归列表

javascript - 使用Express JS部署Elasticsearch

javascript - Microsoft Edge 不会在对 gzipped SVG 文件的 ajax 调用中呈现 SVG 样式元素