Javascript/Fancybox Error?

依然范特西╮ 提交于 2020-01-14 12:52:32

问题


On my page I have 6 boxes below a main image that uses JS to have a nice fade in effect. On this page I also have Fancybox Load at the start of the page (using onload) to show an image that the user needs to see.

The issue is when the user first loads the page one of the boxes will barely show here is a screenshot of the issue: http://screencast.com/t/ROU61nMSgzy

The question is how do I resolve this so this issue does not happen? Note: Once the page is cached this issue does not happen.

Here is the JS for the boxes:

var $j = jQuery.noConflict();

$j(document).ready(function(){
Engine.Initialize();
if( !$j('body').hasClass('index') && !$j('body').hasClass('homepage') ) {
}
});

var Engine = {

Initialize: function() {
    Engine.Homepage_Animation();
},

Homepage_Animation: function() {
    if( !$j.browser.msie ) {
        $j('#homepage-main-item img').hide().fadeIn(700, function(){
            $j(this).css('display', 'block');

            $j('#homepage-boxes .boxes').each(function(i) {
                $j(this).delay(100 * i).animate({
                    opacity: 1
                }, 300);
            });
        });

    } else {
        $j('#homepage-main-item img').css('display', 'block');
        $j('#homepage-boxes .boxes').css('opacity', 1);
    }
},

}

Here is the JS for the Fancybox.

     <script type="text/javascript" >
     var $j = jQuery.noConflict();
$j(document).ready(function(){
 $j("#start").fancybox({
 'padding' : 0
 });
});
</script>

HTML for Fancybox

    <div class="hide">
    <img src="/Images/skin/spacer1x1.png" onload="$j('#start').trigger('click');" />  
<a href="#welcome" id="start"></a>
    <img id="welcome" usemap="#Map" alt="PLEASE VIEW PAGE WITH IMAGES ON" src="/Images/start/start.png" />
    <map id="Map" name="Map">
    <area alt="See Message Examples" href="/artistphotos/" coords="29,431,301,465" shape="rect" />
    <area alt="Enter Site" href="javascript:$j.fn.fancybox.close();" coords="436,433,567,464" shape="rect" />
    </map>
</div> 

Thanks for any help =>


回答1:


If you want fancybox to run first, use the fancybox onComplete callback:

$j(document).ready(function(){
    $j('#start').fancybox({

        'onComplete': function () {
            Engine.Initialize();
        }

    });
});

otherwise, put the fancybox code in after calling your custom init function:

$j(document).ready(function(){
    Engine.Initialize();

    $j("#start").fancybox({
        'padding' : 0
    });
});


来源:https://stackoverflow.com/questions/6935482/javascript-fancybox-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!