I've got a photo slideshow with thumbnails. Next/Previous buttons appear and disappear based on the size of the window; if the thumbnails overflow the window size, the buttons appear. If not, they disappear. My problem is that, at times, they won't come up, or they won't come up for a couple of seconds. At other times they won't disappear. Sometimes it works fine.
I am still pretty new to jQuery and JavaScript. Any suggestions?
// hide previous and next buttons
$('#prev, #next').hide();
// get width of thumbnail list
var thumbsWidth = $('div#thumbs ul').width();
// show/hide next/prev buttons
function buttonVisibility() {
if (thumbsWidth + 225 > screenWidth) {
$('#prev, #next')
.fadeTo('fast', 0.5)
.hover(function(){
$(this).fadeTo('fast', 1);
}, function(){
$(this).fadeTo('fast', 0.5);
});
} else {
$('#prev, #next').fadeTo('fast', 0, function(){
$(this).hide();
});
}
}
// declare global screenWidth variable
var screenWidth
// find width of thumbnail window and show/hide next/prev buttons accordingly
function findWidth(){
screenWidth = $('div#thumbs').width();
buttonVisibility();
}
// perform findWidth() on load and on window resize
findWidth();
$(window).resize(function(){
findWidth();
});