Reputation: 833
Hi all I'm trying to test the size of a window is less than 800px whilst also checking scroll but it's not working I'm sure I just have the syntax incorrect (newbie here).
Here is what I have...
if ($(window).scrollTop() >= origOffsetY && $(window).width() < 801) {
// do something
}
Any ideas?
Upvotes: 1
Views: 108
Reputation: 1074365
That syntax is correct. If it's not working, it's because the values aren't what you expect, not because you have the syntax wrong.
Use the debugger built into your browser to figure it out. To make that easier, you can put things in variables first:
var $win = $(window);
var scrollTop = $win.scrollTop();
var width = $win.width();
if (scrollTop >= origOffsetY && width < 801) {
// do something
}
Now you can put a breakpoint on the if
statement, and inspect the values of the scrollTop
and width
and origOffsetY
variables. Or alternately, add console.log
statements to dump them out (useful for when stopping the script with a breakpoint is awkward).
Upvotes: 1
Reputation: 4270
Try this:
if ($("body").height() > $(window).height() && $(window).width() < 800) {
//your code
}
Upvotes: 0