如何阻止iframe尝试使用父页面的javascript?

时间:2013-05-13 23:30:51

标签: javascript iframe

我正在尝试使用框架将this gallery (warning, nude art content)嵌入到网页中。

我遇到的问题是我有一个下拉菜单,它使用javascript来淡入和淡出页面。这与图库中的javascript相冲突。要查看网站中的图库功能,您可以click here并滚动图库并点击“待售”。它在Chrome和Safari中完美运行。在Firefox中,它不会让图像在底部滚动,因此它们会叠加。我知道这与代码下面的图库第15行有关,但我无法弄清楚如何修复它。

图库代码:

<!DOCTYPE html>
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css.css">
<link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,700italic,400,300,700' rel='stylesheet' type='text/css'>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript" src="http://www.AllenaMistral.com/Play_Site/JSReplaceContent/jquery.easing.1.3.js"></script>
        <script type="text/javascript">
                jQuery.noConflict();
                (function($) {
        $(window).load(function() {
            sliderLeft=$('#thumbScroller .container').position().left;
            padding=$('#outer_container').css('paddingRight').replace('px', '');
            sliderWidth=$(window).width()-padding;
            $('#thumbScroller').css('width',sliderWidth);
            var totalContent=0;
            $('#thumbScroller .content').each(function () {
                totalContent+=$(this).innerWidth();
                $('#thumbScroller .container').css('width',totalContent);
            });
            $('#thumbScroller').mousemove(function(e){
                if($('#thumbScroller  .container').width()>sliderWidth){
                    var mouseCoords=(e.pageX - this.offsetLeft);
                    var mousePercentX=mouseCoords/sliderWidth;
                    var destX=-(((totalContent-(sliderWidth))-sliderWidth)*(mousePercentX));
                    var thePosA=mouseCoords-destX;
                    var thePosB=destX-mouseCoords;
                    var animSpeed=600; //ease amount
                    var easeType='easeOutCirc';
                    if(mouseCoords==destX){
                        $('#thumbScroller .container').stop();
                    }
                    else if(mouseCoords>destX){
                        //$('#thumbScroller .container').css('left',-thePosA); //without easing
                        $('#thumbScroller .container').stop().animate({left: -thePosA}, animSpeed,easeType); //with easing
                    }
                    else if(mouseCoords<destX){
                        //$('#thumbScroller .container').css('left',thePosB); //without easing
                        $('#thumbScroller .container').stop().animate({left: thePosB}, animSpeed,easeType); //with easing
                    }
                }
            });
            var fadeSpeed=200;
                            $('#thumbScroller  .thumb').each(function () {
                $(this).fadeTo(fadeSpeed, 0.6);
            });

            $('#thumbScroller .thumb').hover(
            function(){ //mouse over
                $(this).fadeTo(fadeSpeed, 1);
            },
            function(){ //mouse out
                $(this).fadeTo(fadeSpeed, 0.6);
            }
        );
        });
        $(window).resize(function() {
            //$('#thumbScroller .container').css('left',sliderLeft); //without easing
            $('#thumbScroller .container').stop().animate({left: sliderLeft}, 400,'easeOutCirc'); //with easing
            $('#thumbScroller').css('width',$(window).width());
            sliderWidth=$(window).width();
        });
                    })(jQuery);
    </script></head>
<body>
<h1 style="font: Open Sans">For Sale Pieces</h1>
    <div id="fp_gallery" class="fp_gallery">
        <img src="full_images/torso1.png" alt="" class="fp_preview" style="display:none;"/>
        <div id="fp_loading" class="fp_loading"></div>
        <div id="fp_next" class="fp_next"></div>
        <div id="fp_prev" class="fp_prev"></div>
        <div id="outer_container">
            <div id="thumbScroller">
                <div class="container">
                    <div class="content">
                        <div><a href="#"><img src="thumbs/tthumb1.jpg" alt="full_images/torso1.png" class="thumb" /></a></div>
                    </div>
                </div>
            </div>
        </div>
        <div id="fp_thumbtoggle" class="fp_thumbtoggle">View Thumbs</div>
    </div>
    <div>
    </div>

    <!-- The JavaScript -->
<script type="text/javascript" src="http://www.AllenaMistral.com/Play_Site/JSReplaceContent/jquery.easing.1.3.js"></script>
    <script type="text/javascript">
        jQuery.noConflict();

        (function($) {
        $(function() {
            //current thumb's index being viewed
            var current         = -1;
            //cache some elements
            var $btn_thumbs = $('#fp_thumbtoggle');
            var $loader     = $('#fp_loading');
            var $btn_next       =$('#fp_next');
            var $btn_prev       = $('#fp_prev');
            var $thumbScroller  = $('#thumbScroller');

            //total number of thumbs
            var nmb_thumbs      = $thumbScroller.find('.content').length;

            //preload thumbs
            var cnt_thumbs      = 0;
            for(var i=0;i<nmb_thumbs;++i){
                var $thumb = $thumbScroller.find('.content:nth-child('+parseInt(i+1)+')');
                $('<img/>').load(function(){
                    ++cnt_thumbs;
                    if(cnt_thumbs == nmb_thumbs)
            //display the thumbs on the bottom of the page
            showThumbs(2000);
                }).attr('src',$thumb.find('img').attr('src'));
            }


            //make the document scrollable
            //when the the mouse is moved up/down
            //the user will be able to see the full image
            makeScrollable();

            //clicking on a thumb...
            $thumbScroller.find('.content').bind('click',function(e){
                var $content= $(this);
                var $elem   = $content.find('img');
                //keep track of the current clicked thumb
                //it will be used for the navigation arrows
                current     = $content.index()+1;
                //get the positions of the clicked thumb
                var pos_left    = $elem.offset().left;
                var pos_top     = $elem.offset().top;
                //clone the thumb and place
                //the clone on the top of it
                var $clone  = $elem.clone()
                .addClass('clone')
                .css({
                    'position':'fixed',
                    'left': pos_left + 'px',
                    'top': pos_top + 'px'
                }).insertAfter($('BODY'));

                var windowW = $(window).width();
                var windowH = $(window).height();

                //animate the clone to the center of the page
                $clone.stop()
                .animate({
                    'left': 410 + 'px',
                    'top': windowH/2 + 'px',
                    'margin-left' :-$clone.width()/2 -5 + 'px',
                    'margin-top': -$clone.height()/2 -5 + 'px'
                },500,
                function(){
                    var $theClone   = $(this);
                    var ratio       = $clone.width()/120;
                    var final_w     = 400*ratio;

                    $loader.show();

                    //expand the clone when large image is loaded
                    $('<img class="fp_preview"/>').load(function(){
                        var $newimg         = $(this);
                        var $currImage  = $('#fp_gallery').children('img:first');
                        $newimg.insertBefore($currImage);
                        $loader.hide();
                        //expand clone
                        $theClone.animate({
                            'opacity'       : 0,
                            'top'           : windowH/2 + 'px',
                            'left'          : windowW/2 + 'px',
                            'margin-top'    : '-200px',
                            'margin-left'   : -final_w/2 + 'px',
                            'width'         : final_w + 'px',
                            'height'        : '400px'
                        },1000,function(){$(this).remove();});
                        //now we have two large images on the page
                        //fadeOut the old one so that the new one gets shown
                        $currImage.fadeOut(2000,function(){
                            $(this).remove();
                        });
                        //show the navigation arrows
                        showNav();
                    }).attr('src',$elem.attr('alt'));
                });
                //hide the thumbs container
                hideThumbs();
                e.preventDefault();
            });

            //clicking on the "show thumbs"
            //displays the thumbs container and hides
            //the navigation arrows
            $btn_thumbs.bind('click',function(){
                showThumbs(500);
                hideNav();
            });

            function hideThumbs(){
                $('#outer_container').stop().animate({'bottom':'-200px'},500);
                showThumbsBtn();
            }

            function showThumbs(speed){
                $('#outer_container').stop().animate({'bottom':'-20px'},speed);
                hideThumbsBtn();
            }

            function hideThumbsBtn(){
                $btn_thumbs.stop().animate({'bottom':'-120px'},500);
            }

            function showThumbsBtn(){
                $btn_thumbs.stop().animate({'bottom':'-20px'},500);
            }

            function hideNav(){
                $btn_next.stop().animate({'left':'-50px'},500);
                $btn_prev.stop().animate({'left':'-50px'},500);
            }

            function showNav(){
                $btn_next.stop().animate({'left':'772px'},500);
                $btn_prev.stop().animate({'left':'0px'},500);
            }

            //events for navigating through the set of images
            $btn_next.bind('click',showNext);
            $btn_prev.bind('click',showPrev);

            //the aim is to load the new image,
            //place it before the old one and fadeOut the old one
            //we use the current variable to keep track which
            //image comes next / before
            function showNext(){
                ++current;
                var $e_next = $thumbScroller.find('.content:nth-child('+current+')');
                if($e_next.length == 0){
                    current = 1;
                    $e_next = $thumbScroller.find('.content:nth-child('+current+')');
                }
                $loader.show();
                $('<img class="fp_preview"/>').load(function(){
                    var $newimg         = $(this);
                    var $currImage      = $('#fp_gallery').children('img:first');
                    $newimg.insertBefore($currImage);
                    $loader.hide();
                    $currImage.fadeOut(2000,function(){$(this).remove();});
                }).attr('src',$e_next.find('img').attr('alt'));
            }

            function showPrev(){
                --current;
                var $e_next = $thumbScroller.find('.content:nth-child('+current+')');
                if($e_next.length == 0){
                    current = nmb_thumbs;
                    $e_next = $thumbScroller.find('.content:nth-child('+current+')');
                }
                $loader.show();
                $('<img class="fp_preview"/>').load(function(){
                    var $newimg         = $(this);
                    var $currImage      = $('#fp_gallery').children('img:first');
                    $newimg.insertBefore($currImage);
                    $loader.hide();
                    $currImage.fadeOut(2000,function(){$(this).remove();});
                }).attr('src',$e_next.find('img').attr('alt'));
            }

            function makeScrollable(){
                $(document).bind('mousemove',function(e){
                    var top = (e.pageY - $(document).scrollTop()/2) ;
                    $(document).scrollTop(top);
                });
            }
        });

        })(jQuery);
    </script>

    </body>
</html>

以下是javascript代码的代码以及如何使用它们的示例:

<script type="text/javascript" src="jquery.js"></script>

<script type="text/javascript">$(document).ready(function(){
// Hide div 2 by default
$('#wrapper2').show(); 
$('#faces').hide();
$('#hands').hide();
$('#torso').hide();
$('#about').hide();
$('#contact').hide();
$('#collab').hide();
$('#newgallery').hide();
$('.forsale').hide();
$('#calendar').hide();
});  

});



</script>

如果这是另一个问题的重复,我很抱歉。我试着一遍又一遍地找不到能让它完美运作的东西。任何帮助将不胜感激。如果我必须删除主页上的javascript淡入淡出,我会,但我真的希望有一个解决方法,但不删除它。

感谢您的帮助!

0 个答案:

没有答案