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 7860733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:24:27+00:00 2026-06-02T22:24:27+00:00

I think this question is best explained by giving you a jsFiddle . In

  • 0

I think this question is best explained by giving you a jsFiddle. In that example, when the user clicks on of the gallery items, an image is appended to the div with id="showimage". What I cannot work out how to do is pass in the parameter of the image clicked, and display that image instead of an absolute one.

It should function as follows:

  • If image 1 is clicked, image 1 should be appended into showimage.
    It should animate from width 0px to width 10% of the parent div.
  • If image 1 is clicked again, it should collapse: it should animate
    from width 100% to width 0px
  • If any other img is clicked while there is already an image in showimage, the image already inside should collapse, and the new one expand in its place

I think this would be best accomplished by 3 functions:

  1. Expand – append to showimage and animate from 0px to 100%
  2. Collapse – animate from 100% to 0px and remove from showimage
  3. Replace – call collapse on the image already in showimage, and call expand on the image clicked

Thanks in advance, any help would be much appreciated.

  • 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-06-02T22:24:29+00:00Added an answer on June 2, 2026 at 10:24 pm

    I managed to solve the problem, and you can see a live jsFiddle example here.

    I kept the code really neat for this one – 3 separate functions, and 1 if statement to check if the showimage div had content.

    The jQuery I used was as follows:

    var add_image = function(clicked) {
        var image_create = '<img src="' + clicked + '">';
        $('#showimage').hide().append(image_create).slideDown(400);
    };
    
    var change_image = function(clicked) {
        $('#showimage img').slideUp(400, function() {
            $(this).remove();
            add_image(clicked);
        });
    };
    
    var remove_image = function() {
        $('#showimage img').slideUp(400, function() {
            $(this).remove();
        });
    };
    
    $('.gallery').click(function() {
        var len = $('#showimage').children().length;
        var clicked = $("img", this).attr('src');
        if (len === 0) {
            add_image(clicked);
        } else if (len === 1) {
            change_image(clicked);
        }
    });
    
    $('#showimage').click(function() {
        remove_image();
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think my question is best explained via an example: Suppose I want to
I think this is just a Best Practices question, but I was wondering if
This is the best way I can think of phrasing this question, given this
I think the issue is explained best with an example. public class MyService {
I think this question may end up being a bit subjective so I'm marking
I think this question is really about my understanding of Garbage collection and variable
I don't think this question has been asked before. I'm a bit confused on
I got this question in a programming test. Do you think this question is
I am using PrimeFaces p:messages but I think this question applies equally to h:messages
I mostly develop using C#, but I think this question might be suitable for

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.