JQuery Novice to Ninja and Firefox

I am on Ch.4 and need some help with the custom lightbox. It works in Safari and Chrome, but not Firefox (3.6.8). I’ve been floundering on this one for awhile and could use some help with the cross browser struggle.

Thanks.

Everybody please calm down. I figured it out.

Get rid of: console.log(“The calculated position is:”);
console.log(top,left);

Found the info in the “Novice to Ninja” forum.

Research before posting. Lesson learned.:nono:

Thanks for the response.

This is the JS:

$(document).ready(function(){
$(‘a.lightbox’).click(function(e) {
$(‘body’).css(‘overflow-y’, ‘hidden’); // hide scrollbars!

$('<div id="overlay"></div>')
  .css('top', $(document).scrollTop())
  .css('opacity', '0')
  .animate({'opacity': '0.5'}, 'slow')
  .appendTo('body');
  
$('<div id="lightbox"></div>')
  .hide()
  .appendTo('body');
  
$('<img />')
  .attr('src', $(this).attr('href'))
  .load(function() {
    positionLightboxImage();
  })
  .click(function() {
    removeLightbox();
  })
  .appendTo('#lightbox');

return false;;

});
});

function positionLightboxImage() {
var top = ($(window).height() - $(‘#lightbox’).height()) / 2;
var left = ($(window).width() - $(‘#lightbox’).width()) / 2;
console.log(“The calculated position is:”);
console.log(top,left);
$(‘#lightbox’)
.css({
‘top’: top + $(document).scrollTop(),
‘left’: left
})
.fadeIn();
console.log(‘A jQuery selection:’);
console.log($(‘#lightbox’));
}

function removeLightbox() {
$(‘#overlay, #lightbox’)
.fadeOut(‘slow’, function() {
$(this).remove();
$(‘body’).css(‘overflow-y’, ‘auto’); // show scrollbars!
});
}

The HTML that it refers to looks like this:

<a class=“lightbox” href=“images/molotov.png”>molotov</a>

Hi kanesaws, welcome to SitePoint! :slight_smile:

Could you post a link to what you have currently, or some code that we could test out? Otherwise there’s not much anyone can do.