Reputation: 8764
I have the following script that is working great, but I want to wrap it in an if statement that only runs this script when the window height is larger than the #tip element. What do I add?
$(document).scroll(function () {
if($(window).scrollTop() >= 40){
$('#tip').css({'position' : 'fixed', 'top' : '20px', 'left' : '50%', 'margin-left' : '250px' });
}
if($(window).scrollTop() <= 40){
$('#tip').css({'position' : 'absolute', 'top' : '15px', 'left' : '', 'margin-left' : ''});
}
console.log($(window).scrollTop());
});
Upvotes: 2
Views: 286
Reputation: 18219
simply
$(document).scroll(function () {
if ($(window).height() > $('#tip').height()) {
... your code here
}
});
Upvotes: 4