I have the following code:
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');
}
}
And in the function handleWindowResize(), I had a variable that I set globally as isMapVisible. and is calling another function isVisible(). I found out that when I replace that line of code with isMapVisible = $('.search__map').is(':visible'), I am able to get the correct result, but if my code is as copied above, I would get undefined. Any idea why?
asked Jul 26, 2015 at 12:48
Chris Yeung
2,7336 gold badges37 silver badges62 bronze badges
-
5You forget return in isVisible function.jcubic– jcubic2015年07月26日 12:49:02 +00:00Commented Jul 26, 2015 at 12:49
-
thanks! very rookie.Chris Yeung– Chris Yeung2015年07月26日 13:03:45 +00:00Commented Jul 26, 2015 at 13:03
1 Answer 1
That is because you are not returning anything in your function:
function isVisible(selector) {
return $(selector).is(':visible');
}
answered Jul 26, 2015 at 12:50
Sebastian Nette
7,9022 gold badges20 silver badges18 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js