如何向UI选项卡添加交叉淡入淡出?

Yos*_*sef 4 jquery jquery-ui fade jquery-ui-tabs

您好我从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>
Run Code Online (Sandbox Code Playgroud)

此时,作为一个显示的选项卡淡出,在出现下一个选项卡之前留下一个空白区域.

我想要发生的是当tab1淡出,tab 2淡入 - 创建一个交叉淡入淡出.

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

提前致谢

Ric*_*ard 6

我认为Jquery UI默认情况下不能这样做.但是,jQuery Tabs UI 附带了一个事件"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));

        }

    });
});
Run Code Online (Sandbox Code Playgroud)

现场演示:

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