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

  • SEARCH
  • Home
  • 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 4084384
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:26:00+00:00 2026-05-20T18:26:00+00:00

In order to perform some animations I need to add a second image, identical

  • 0

In order to perform some animations I need to add a second image, identical to the one I already have in my document, with the value of top property equal to the height of the image.

Right now I do:

$("#blur").after("<img src='someimg.jpg' id='above' >");
var t = -($("#blur").height());
$("#above").animate({top: t}, 1);

But it’s rather ugly – one can see the moment when new element is created and then moved to the right position.

Is there any way to place the second <IMG> with automatically calculated top walue?

My goal is to have two identical images stacked one over the another.

  • 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-20T18:26:00+00:00Added an answer on May 20, 2026 at 6:26 pm

    Sure, just set the ‘top’ CSS style property before adding the new image to the DOM:

     var t = $('#blur').height();
     $('<img src="someimg.jpg" id="above">')
     .css('top', -t)
     .insertAfter('#blur');
    

    In practice though, it’s better to set the position attribute to absolute, since otherwise that top attribute will be relative to the element’s default position, instead of relative to the origin of the first image.

     var t = $('#blur').height();
     $('<img src="someimg.jpg" id="above">')
     .css({
        position:'absolute',
        top: 0, left: 0       // should be implicit anyway
     })
     .insertAfter('#blur');
    

    p.s. use single quotes around your strings and HTML snippets, so that you can use the correct double-quote character for HTML attributes.

    EDIT – for a more general solution (see http://jsfiddle.net/bE7TH/)

    function overlay(selector, new_id) {
        $(selector)
        .clone()
        .removeAttr('id')
        .attr('id', new_id)
        .css({
            position: 'absolute', left: 0, top: 0
        })
        .insertAfter(selector);
    }
    

    I think the original element will have to have a position property of fixed or absolute for this to work properly, and you may also need to account for any margin or padding too.

    • 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.