简体   繁体   English

jquery-ui选项卡与fadeIn?

[英]jquery-ui tabs with fadeIn?

I have a small JQuery Tabs widget in a sidebar that fades in when the page loads, discreetly calling attention to itself and the interesting content behind the tabs. 我在边栏中有一个小的“ JQuery Tabs”小部件,该小部件在页面加载时逐渐淡入,谨慎地引起对自身的关注以及这些标签后面的有趣内容。

To build on this effect it might be nice if the individual tabs could fade in one after the other. 要建立这种效果,最好是各个选项卡可以一个接一个地淡入淡出。

Can this be done, and if so, how? 可以做到吗?如果可以,怎么做?

This will make when select the tab desappear, and when it is shown appear! 选择消失的选项卡,并在其显示时,这将使它出现!

$('.tabs').tabs({
        select: function(event, ui) {
            $(ui.panel).animate({opacity:0.1});
        },
        show: function(event, ui) {
            $(ui.panel).animate({opacity:1.0},1000);
        }
});

由于选项卡只是li元素,因此可以在第一次加载页面时将所有选项卡设置为不display:none吗?然后使用JQuery的Fadehttp://jqueryui.com/demos/effect/ )效果分别淡化每个li元素在吗?

I found a discussion of my problem here: http://p.karageorgakis.com/blog/jquery_simulating_a_delay_function_between_fade_in_out_effects/ 我在这里找到了关于我的问题的讨论: http : //p.karageorgakis.com/blog/jquery_simulating_a_delay_function_between_fade_in_out_effects/

Among the solutions proposed, the javascript setTimeout() trumped the other solutions, at least for my purpose. 在提出的解决方案中,javascript setTimeout()胜过其他解决方案,至少出于我的目的。

Here is the code I went with: 这是我使用的代码:

$(function() {
    $("#tabs").tabs();
    $("#tabs").fadeIn(500);
    $("#li1").fadeIn(500);
    setTimeout('$("#li2").fadeIn(500)', 300);
    setTimeout('$("#li3").fadeIn(500)', 600);
    setTimeout('$("#li4").fadeIn(500)', 900);
});

The tabs widget itself as well as the list items are all set to display:none at the outset. 选项卡小部件本身以及列表项都一开始就设置为display:none

There was another issue that I will share, because it led me to the nice fade solution. 我将分享另一个问题,因为它使我找到了不错的淡入淡出解决方案。

This widget needed to float to the left of some other content, but also needed to be hidden until fully instantiated by JQuery. 这个小部件需要浮动到其他一些内容的左侧,但也需要隐藏,直到被JQuery完全实例化为止。 fadeIn() wasn't working with an element set to visibility:hidden ; fadeIn()不适用于设置为fadeIn() visibility:hidden的元素; it had to be display:none , but this caused the widget to displace the surrounding content and appear abruptly, which looked really awful. 它必须是display:none ,但是这导致小部件替换周围的内容并突然出现,这看起来确实很糟糕。 Fading in was a way to mitigate that. 淡入是减轻这种情况的一种方法。

In retrospect, maybe I could block off the (known) dimensions of the tabs widget, anyway I like the result I got! 回想起来,也许我可以阻止选项卡小部件的(已知)尺寸,无论如何,我都喜欢得到的结果!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM