0

我正在这里的客户网站上工作:http: //www.marcusleighcopy.co.uk/about

在 flash 弹出窗口之后,您应该会看到一个 about 页面,在图像下方有一个我已经构建的推荐设备。实际设备的 JS 很好,但是如果当前未查看窗口,我想阻止设备执行任何操作(因为构建了一个奇怪的队列,并且当焦点返回到窗口时立即全部触发)。

无论如何,我修改了我的代码并添加了这个:(就像这里的另一个问题一样)

if (/*@cc_on!@*/false) 
            { 
                // check for Internet Explorer
                document.onfocusin = onFocus;
                document.onfocusout = onBlur;
            } 
            else 
            {
                window.onfocus = onFocus;
                window.onblur = onBlur;
            }

我的推荐装置是这样的:

function onBlur() 
            {
                document.body.className = 'blurred';
            };
            function onFocus(){
                document.body.className = 'focused';
                    // Testimonial fade in/out
                var testimonial_count = $('div.testimonial').size();
                if (testimonial_count)
                {
                    var testimonials = [];

                    $('div.testimonial').each(function(){
                        testimonials.push($(this));
                    });

                    show_testimonials(0);

                }

                function show_testimonials(currentIndex)
                {
                    testimonials[currentIndex].fadeIn(400);

                    if ($('body').hasClass('blurred'))
                    {
                        return false;
                    }

                    setTimeout(function(){

                        testimonials[currentIndex].fadeOut(400);
                        if (currentIndex + 1 >= testimonial_count)
                        {
                            show_testimonials(0);
                        }
                        else
                        {
                            show_testimonials(currentIndex + 1);
                        }

                    }, 10000);
                }
            };

在 SAFARI 中,窗口最初没有聚焦。如果您单击关闭 Safari,然后再单击它,则推荐会按预期显示。如有必要,如何让窗口立即触发 onFocus 功能?

4

1 回答 1

1

这将触发 DOM 就绪的焦点事件:

$(function(){
     $(document).focus();
};
于 2012-02-28T13:09:09.417 回答