【问题标题】:Jquery dialog with fadeIn/fadeOut and load issues带有淡入/淡出和加载问题的 Jquery 对话框
【发布时间】:2013-02-12 21:24:33
【问题描述】:

我的客户在加载内部页面时想要一个淡入/淡出图像。这是有问题的页面:http://angelynngrant.com/mei3/ouragency.html

问题: (1)fadeIn 不工作; (2) fadeOut 有效,但在 'destroy' 之前留下一个幻影矩形; (3) 经常在加载(和刷新)时,模态显示在窗口的左上角,然后“跳”到位以淡出。

我已经调整了我的 CSS 以使对话框的大多数元素消失和/或透明(例如 .ui-dialog .ui-dialog-titlebar {visibility:hidden; background:transparent;})。

我在标题中有负载:

<script type="text/javascript">                                         
    $(window).load(function() {                         
        $("#ModalSlide7").dialog({
            width: 564,
            height: 808,
            modal: true
        }); 
        $(".ui-dialog-titlebar").hide(); 
    });
</script>

我在正文中有其余的模态:

<div id="ModalSlide7">
    <img id="slide7" src="images/7.jpg" alt="Game of Authors vintage game">

    <script type="text/javascript">
        $('#slide7').fadeIn(3000, function() {
            $('#slide7').fadeOut(3000).queue(function (next) {
                $('#ModalSlide7').dialog('destroy').remove();
            });
        });
    </script>
</div>

任何帮助将不胜感激。

(注意:网站设计/样式尚未完成。)

【问题讨论】:

  • 我没有太多时间研究这个,但有两个想法要考虑。首先可能是 FadeIn 没有做任何事情,因为图像已经是 100% 的不透明度。不确定它是否需要从 0 开始,或者淡入淡出是否会使其从 0 开始。其次是我认为对话框在弹出时会在页面周围移动 html 元素。由于您在窗口加载时打开它,我敢打赌,当对话框在页面周围移动元素时,fadeIn 已经开始并且会被缩短。也许您可以在对话框的打开事件上启动淡入淡出,并使用 css 隐藏 img 开始。
  • 这里是公开活动:api.jqueryui.com/dialog/#event-open

标签: jquery jquery-ui dialog modal-dialog


【解决方案1】:

Here is a demo我把我认为你想要的东西放在一起。希望这会有所帮助!

$(function () {

    // On document ready setup your dialog to define what happens
    // when it gets shown and hidden and some basic settings
    $("#dialog").dialog({
        autoOpen: false,
        draggable: false,
        resizable: false,
        show: {
            effect: 'fade',
            duration: 2000
        },
        hide: {
            effect: 'fade',
            duration: 2000
        },
        open: function(){
            $(this).dialog('close');
        },
        close: function(){
            $(this).dialog('destroy');
        }
    });

    $(".ui-dialog-titlebar").remove();

    // Finally open the dialog! The open function above will run once
    // the dialog has opened. It runs the close function! After it has
    // faded out the dialog is destroyed
    $("#dialog").dialog("open");
});

我认为您的困惑来自 jquery ui 对话框和一般 jQuery 函数提供的混合功能(例如,您使用 fadeIn 而不是在调用 show 函数时将对话框配置为淡入)。 Here is a big list 的所有功能和大量示例!

【讨论】:

  • 非常感谢您的帮助。它可以工作,尽管在发生淡入/淡出/销毁时不会使页面的其余部分变灰。不过,我不确定我的客户是否需要变灰。事实上,我会尝试劝阻她不要使用这些弹出式效果。我认为重复观看可能会很烦人。我在客户的愿景和好的设计之间左右为难。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-03-26
  • 2014-10-02
  • 1970-01-01
  • 2011-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多