本文介绍了Javascript"---未定义";错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有此功能"resizePortfolio",稍后通过执行"resizePortfolio();"来调用它但是控制台显示"Uncaught ReferenceError:未定义resizePortfolio".是为了使幻灯片显示响应,但由于某种原因,它给出了一个错误,并且我不明白为什么...

I have this function "resizePortfolio" and I call it later by doing "resizePortfolio();" But the console says "Uncaught ReferenceError: resizePortfolio is not defined." It's to make my slideshow responsive, but for some reason it's giving an error and I don't understand why...

非常感谢您的帮助.

function resizePortfolio() {
    slideshowTitleHeight = $('.slideshow_title').height() + 20;
    slideshowControlsHeight = $('.slideshow_controls').height() + 20;
    if (showFullScreen == true) {
        _w = $('#wrapper').width() - (slideshowPaddingLeft + slideshowPaddingRight); // width for the slideshow item
    } else {
        _w = $('#wrapper').width() - menuWidth - (slideshowPaddingLeft + slideshowPaddingRight); // width for the slideshow item
    }
    _h = $('#content').height() - (slideshowPaddingTop + slideshowPaddingBottom + slideshowControlsHeight + slideshowTitleHeight); // height for the slideshow item
    $('.slideshow, .slideshow li, .slideshow li, .slideshow li table, .slideshow li table td').css({'width':_w, 'height':_h});
    $('.slideshow li table td  img').css({'max-height':_h,'max-width':_w});

    $(slideshowContainer).children('li').each(function() {
        _imgH = $(this).find('img').height(); // height for the slideshow image
        _imgW = $(this).find('img').width(); // width for the slideshow image
        if ($(this).hasClass('assettype2')) {
            hasVideo = true;
        }
        // position for the share overlay
        if (hasVideo == true) {
            $(slideshowShareContainer, this).height(_h).width(_w);
            $(slideshowShareContainer, this).children('div').height(_h).width(_w);
            $('.slideshow_share_links', this).width(_w/2);
            var margin = _w/2;
            var marginTop = (_h/2) - (_h/2);
            $(slideshowShareContainer, this).css({'marginLeft': -margin});
        } else {
            $(slideshowShareContainer, this).height(_imgH).width(_imgW+1);
            $(slideshowShareContainer, this).children('div').height(_imgH).width(_imgW);
            $('.slideshow_share_links', this).width(_imgW/2);
            $('.slideshow_share_links.blog', this).width(_imgW);
            var margin = _imgW/2;
            var marginTop = (_h/2) - (_imgH/2);
            $(slideshowShareContainer, this).css({'marginLeft': -margin});
        }
    });
}

推荐答案

确保通话:

$(window).on("resize", resizePortfolio);

$(document).ready(function() {...})主体内部,因为函数名称的范围就是该函数.

is inside the $(document).ready(function() {...}) body, because the scope of the function name is just that function.

这篇关于Javascript"---未定义";错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-28 20:32