Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6320937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:03:47+00:00 2026-05-24T16:03:47+00:00

I am creating a custom lightbox which is basically a large image generated from

  • 0

I am creating a custom lightbox which is basically a large image generated from a small image in a slider. The transition from small to large image is animated. It works ok but after several clicks/triggers, it becomes real slow that you can see frames displaying a split second until it reaches the final state. Are there issues with animate method that I am not aware of? Or am I using it wrong, I mean are there any standards in using animate method? Or my code just sucks? Here’s my code.

var $j = jQuery.noConflict();
$curIndex = 0;

function curIndex(){
    return $curIndex;
}

function next($index, $direct){

    var $sliderList = $j('#mainSlider li');
    var $imgs = {};

    $sliderList.map(function(index){
        $imgs[index] = $j(this).children('img').attr('src');     
    });

    if ($index == -1) {
        return $imgs[$index + 1]; 

    } else if ($index == $sliderList.length) {
        return $imgs[$index - 1]; 

    } else {

        $curIndex = $index;
        return $imgs[$index];    
    }  
}

function get_size($type) {

    var $width = $j(window).width(); 
    var $height = $j(window).height();
    var $top = $j(window).height();  

    if ($type == 'width') {
        return $width;
    } else if ($type == 'height') {
        return $height;
    } else {
        return $top;
    }
}

$j(document).ready(function(){

    var $imgStyle = {
        'top' : get_size('top') * .075 + 'px',
        'left' : get_size('width') * .125 + 'px',
        'width' : get_size('width') * .75 + 'px', 
        'height' : get_size('height') * .85 + 'px',
        'position':'absolute', 
        'z-index':'200'
    };

    $j('body').append(
        '<div class="arj-lightbox-con"><div class="arj-lightbox-shade"></div></div>'
    );

    $j('#mainSlider img').click(function(){

        var $offset = $j(this).offset();
        var $clckdImage = $j(this);

        $j('.arj-lightbox-con').fadeIn().append('<div class="arj-controls"></div><div class="arj-caption"></div>');

        $j('.arj-controls').css({
            'top' : get_size('top') * .075 + 'px',
            'left' : get_size('width') / 2 - 50 + 'px'  
        }).append('<span class="arrow back"></span><span class="close"></span><span class="arrow forward"></span>');

        $j('.arj-caption').css({
            'bottom' : get_size('top') * .075 + 'px',
            'left' : get_size('width') * .125 + 'px',
            'width' : get_size('width') * .75 + 'px'
        });

        $j('.close').click(function(){
            $j('.arj-lightbox-con').css('display', 'none');
            $j('.arj-controls').remove();
            $j('.arj-caption').remove();
        });

        var $onClickSrc = next($j(this).parent().index());

        $j('.arj-lightbox-con').append('<img src="' + $onClickSrc + '" alt="arj-lightox" />');

        $j('.arj-lightbox-con img').css({
            'width' : $clckdImage.css('width'), 
            'height' : $clckdImage.css('height'),
            'top': $offset.top,
            'left': $offset.left,
            'right': $offset.right,
            'position':'absolute', 
            'z-index':'200',
        }).animate({
            top : get_size('top') * .075 + 'px',
            left : get_size('width') * .125 + 'px',
            width : get_size('width') * .75 + 'px', 
            height : get_size('height') * .85 + 'px'
        }, 250, function(){
            $j('.arj-controls').fadeIn();
            $j('.arj-caption').fadeIn();
        });

        $j('.forward').click(function(){
            var $nextForwardSrc = next(curIndex() + 1, 1);
            var $newImage =  '<img src="' + $nextForwardSrc + '" alt="arj-lightox" />';
            $j('.arj-lightbox-con').append($newImage);
            $j('.arj-lightbox-con img').css($imgStyle); 
        });

        $j('.back').click(function(){
            var $nextBackSrc = next(curIndex() - 1, -1);
            var $newImage =  '<img src="' + $nextBackSrc + '" alt="arj-lightox" />';
            $j('.arj-lightbox-con').append($newImage);
            $j('.arj-lightbox-con img').css($imgStyle);

        });
    }); 
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T16:03:48+00:00Added an answer on May 24, 2026 at 4:03 pm

    Your code just sucks, you are doing many things that could be improved. Here is the link to the lightbox code for reference:

    http://trip.wtfmarketing.com/wp-content/themes/charleycoffee/arj.lightbox.js

            $j('.arj-lightbox-con').fadeIn().append('<div class="arj-controls"></div><div class="arj-caption"></div>');
    

    Looking at this line, there are two problems. One, every time you click on something, you are running a jQuery selector which hits every single DOM node looking for ANY element with the class name of “.arj-lightbox-con”. You can cache this simply by assigning it to a variable.

    But the worst part is you are constantly appending. You are making the contents of .arj-lightbox-con longer and longer each time, filling it with images. When that element fades in, the browser is also fading in the dozens of images in the lightbox even though you can’t see them. You never clear it. This is a simple fix:

    $j('.arj-lightbox-con').empty().fadeIn()... blah blah
    

    General debugging tip: If you had inspected your lightbox element with Firebug you would have seen the image pileup and could have helped with debugging.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.