I'm coming close to finishing a site where there are a number of jQuery functions going on. They all work, but the page is just running a bit too clunky. The fading in and out is just not as smooth as it should be, especially on the contact link, and the auto page scrolling is a little jumpy.
I've cached as many selectors as I could, I've minified the script, I'm using the latest jquery, but not much has changed. I'm wondering if someone could tell perhaps why?
$(document).ready(function ()
{
/*--------Variables -----------------------------------*/
var trigger1 = $('#trigger1');
var trigger2 = $('#trigger2');
var trigger3 = $('#trigger3');
var trigger4 = $('#trigger4');
var closed = $('.close');
var scrollContainer = $('#scrollContainer');
var scrollOpen = $('#scrollOpen');
var movie = $('#movie');
var openBook = $('#openBook');
var openChest = $('#openChest');
var theLetter = $('#theLetter');
var synopsis = $('#synopsis');
var shine2 = $('#shine2');
var bookGlow = $('#bookGlow');
var chestGlow = $('#chestGlow');
var iframe = $('iframe');
var contact = $('#contact');
var contactWrapper = $('#contactWrapper');
/*--------End Variables --------------------------------*/
/*-------------------Auto Page Scroll-------------------*/
$('#navigation_container').localScroll({
duration: 1000
});
$('#top').localScroll({
duration: 1000
});
/*-----------------End Auto Page Scroll-------------------*/
/*-------------------Contact Form-------------------------*/
$('ul#Navlist li:last').click(function () {
contact.delay(1000).fadeIn(3000);
var viewportWidth = $(window).width();
var viewportHeight = $(window).height();
var popupWidth = contactWrapper.width();
var popupHeight = contactWrapper.height();
var leftPos = (viewportWidth/2)-(popupWidth/2);
var topPos = (viewportHeight/2)-(popupHeight/2);
contactWrapper.css('top', topPos).css('left', leftPos);
closed.delay(1500).fadeIn(3000);
});
closed.click(function () {
contact.delay(700).fadeOut('slow');
});
/*-------------------End Contact Form-------------------*/
trigger1.click(function () {
scrollContainer.fadeIn('slow');
scrollOpen.delay(1000).animate({
right: 60
}, {
duration: 1000
});
closed.delay(1500).fadeIn('slow')
});
closed.click(function () {
scrollOpen.animate({
right: -579
}, {
duration: 1000
});
scrollContainer.delay(700).fadeOut('slow');
});
trigger2.click(function () {
movie.delay(1000).animate({
bottom: 0
}, {
duration: 1000
});
closed.delay(1500).fadeIn('slow')
});
closed.click(function () {
iframe.attr('src', iframe.attr('src'));
movie.delay(1000).animate({
bottom: -500
}, {
duration: 1000
});
});
trigger3.click(function () {
openBook.fadeIn(1000);
closed.delay(1000).fadeIn('slow')
});
closed.click(function () {
openBook.delay(700).fadeOut('slow');
});
trigger4.click(function () {
openChest.fadeIn('slow');
});
openChest.click(function () {
$(this).fadeOut('slow');
theLetter.delay(1000).fadeIn('slow');
closed.delay(1500).fadeIn(3000);
});
closed.click(function () {
theLetter.delay(700).fadeOut('slow');
});
/*--------------- Audio Begin ------------------------------*/
var audio = $('#magic')[0];
$('#trigger1, #trigger2, #trigger3, #trigger4').mouseenter(function () {
audio.play();
$('#synopsis,#shine2,#chestGlow,#bookGlow').fadeIn('slow');
});
$('#trigger1, #trigger2, #trigger3, #trigger4').mouseleave(function () {
$('#synopsis,#shine2,#chestGlow,#bookGlow').fadeOut('slow');
});
/*---------------End Audio -----------------------------*/
})