Reputation: 171
I'm having difficulty getting this scrip to work properly:
$(window).(function(){
var maxHeight = 330;
if (maxHeight < 331)
$('.ui-lightbox-mid').addClass('addScroll');
else
$('.ui-lightbox-mid').removeClass('addScroll');
});
What I'm trying to do is confine a lightbox to 330px tall without adding a scrollbar all the time. I'm adding a class ('addScroll' //which is just overflow-y:scroll css wise) when the content is larger than 330px in order to add scrolling to the lightbox.
Can anyone help?
thanks Joe
Upvotes: 0
Views: 575
Reputation: 87073
$(window).function(){ .. })
is not proper structure. Instead of it use:
$(window).load(function() { .. })
But in proper jQuery way:
$(document).ready(function() { .. })
.
OR
$(function() { .. })
Full Code
$(document).ready(function() {
var maxHeight = 330,
lightbox = $('.ui-lightbox-mid'), // caching reference
lightboxHeight = lightbox.height(); // get the current height
// of lightbox, to compare
// with maxHeight
if ( maxHeight < lightboxHeight )
lightbox.addClass('addScroll');
else
lightbox.removeClass('addScroll');
});
Upvotes: 3
Reputation: 13867
I think you should wait until to document-ready event was triggered, before it doesn't make sense to retrieve the height anyhow. This can be done with $(document).ready(function() { ... })
Upvotes: 0