jquery - 如何向 UI 选项卡添加淡入淡出效果?

标签 jquery jquery-ui jquery-ui-tabs fade

您好,我从 http://forum.jquery.com/topic/how-to-add-a-cross-fade-to-ui-tabs 复制问题,因为我也有同样的问题。

大家好

我已经使用标准 UI 选项卡代码设置了选项卡式界面。

<script type="text/javascript">
$(function() {
$("#tabbedArea").tabs({ fx: { opacity: 'toggle' } }).tabs('rotate', 6000, 'true')
});
</script>

此时,一个显示的选项卡会淡出,在下一个选项卡出现之前留下空白。

我希望发生的是当 tab1 淡出时,tab 2 淡入 - 创建交叉淡入淡出。

谁能告诉我如何实现这个目标?

提前致谢

最佳答案

我认为 Jquery UI 默认情况下无法执行此操作。然而 jQuery 选项卡 UI comes with a event "show" ,您可以在其中编写一些自定义代码来自行切换选项卡。

$(document).ready(function() {
    $("#tabs").tabs({

        show: function(event, ui) {

            var lastOpenedPanel = $(this).data("lastOpenedPanel");

            if (!$(this).data("topPositionTab")) {
                $(this).data("topPositionTab", $(ui.panel).position().top)
            }         

            //Dont use the builtin fx effects. This will fade in/out both tabs, we dont want that
            //Fadein the new tab yourself            
            $(ui.panel).hide().fadeIn(500);

            if (lastOpenedPanel) {

                // 1. Show the previous opened tab by removing the jQuery UI class
                // 2. Make the tab temporary position:absolute so the two tabs will overlap
                // 3. Set topposition so they will overlap if you go from tab 1 to tab 0
                // 4. Remove position:absolute after animation
                lastOpenedPanel
                    .toggleClass("ui-tabs-hide")
                    .css("position", "absolute")
                    .css("top", $(this).data("topPositionTab") + "px")
                    .fadeOut(500, function() {
                        $(this)
                        .css("position", "");
                    });

            }

            //Saving the last tab has been opened
            $(this).data("lastOpenedPanel", $(ui.panel));

        }

    });
});

现场演示:

http://jsfiddle.net/FFTzU/7/

关于jquery - 如何向 UI 选项卡添加淡入淡出效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4639277/

相关文章:

javascript - 选择单选按钮并单击“保存”按钮时显示特定的 Bootstrap 模式

javascript - 无法放入 Rubaxa 的 Sortable.js 中的克隆容器

jquery - 如何为外部 css 文件添加额外的元素样式?

javascript - 基于 JSON 创建 jquery 选项卡

jquery ui 主题 api

javascript - 通读表格并显示日期

jQuery - 选择动态创建的 div

javascript - 来自表单提交的数据与来自 Ajax 的数据

javascript - Cart to Fly Uncaught TypeError : Cannot read property 'top' of undefined

css - 从事件的 jQuery UI 选项卡中删除大纲?