簡體   English   中英

未在javascript中調用函數

[英]Function not being called in javascript

我有以下代碼:

function isVisible(selector) {
    $(selector).is(':visible');
}

var isMapVisible;
var initialWindowWidth = window.innerWidth;
/* Window Resize Helper */
function handleWindowResize() {
    isMapVisible = isVisible('.search__map');
    if (window.innerWidth > 768) {
        var windowHeight = window.innerHeight,
        searchResultsHeight = windowHeight - $('.search__results').position().top,
        searchMapHeight = windowHeight - $('.search__map').position().top;
        $('.search__results').height(searchResultsHeight);
        $('.search__map').height(searchMapHeight);
        if (initialWindowWidth < 769) {
            /* 
                This is a hack to trigger the map to show up if initial windowWidth causes the map to hide. 
                it only triggers once.
            */
            resizeMap();
            map.setZoom(map.getZoom() - 1);
            initialWindowWidth = 1000;
        }
    } else {
        $('.search__results').height('auto');
    }
}

並且在handleWindowResize()函數中,我有一個全局設置為isMapVisible的變量。 並正在調用另一個函數isVisible() 我發現,當我用isMapVisible = $('.search__map').is(':visible')替換該行代碼時,我可以得到正確的結果,但是如果我的代碼如上復制,我會變得不確定。 知道為什么嗎?

這是因為您沒有在函數中返回任何內容:

function isVisible(selector) {
    return $(selector).is(':visible');
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM