Javascript "——未定义"错误

Javascript "--- is Not Defined" Error

本文关键字:quot 错误 未定义 Javascript      更新时间:2023-09-26

我有这个函数"resizePortfolio",我稍后调用它"resizePortfolio();"但是控制台显示"未捕获的ReferenceError: resizePortfolio未定义"。这是为了让我的幻灯片响应,但由于某种原因,它给出了一个错误,我不明白为什么…

我真的很感激你的帮助。
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() {...})体内,因为函数名的作用域就是那个函数。