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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:05:25+00:00 2026-05-24T23:05:25+00:00

HTML code consists of a div with spans of two types of classes: hide

  • 0

HTML code consists of a div with spans of two types of classes: “hide” and “keep.”

<div>
    <span class"hide">Lorem ipsum dolor sit amet, </span>
    <span class="keep">consectetur</span>
    <span class"hide"> adipisicing elit, sed do </span>
    <span class="keep">eiusmod</span>
</div>

JQuery code is in place that selects spans with class hide so that they may be faded out, leaving only the spans of class “keep” visible within the div.:

last.children("span.hide").fadeOut();

Question: How can I animate the movement of the “keep” spans from their original positions in the text to their final visible positions?

The animation code is not a challenge to write so long as the initial and final position of each span can be identified. The challenge(, I suspect,) is to determine the final position of each span once the “hide” class spans are hidden. Note that, despite my example code, there is an arbitrary number of “hide” and “keep” spans within the div, each with arbitrarily large contents.

Note: JQuery 1.6+ is used.


Bonus Question: How can I animate the movement of the “keep” spans back to their original positions after fading in the “hide” spans?

  • 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-24T23:05:26+00:00Added an answer on May 24, 2026 at 11:05 pm

    Here’s my raw, mostly untested thought:

    1. Get the positions of the “keep” elements.
    2. Hide the “hide” elements with display: none.
    3. Get the new positions of the “keep” elements.
    4. Show the “hide” elements again.
    5. Hide the “hide” elements with visibility: hidden (so they retain their place in the layout)
    6. Animate the positions of the “keep” elements relative to their normal position.

    Because you do all of that without yielding, the user should just see the animation (live example):

    var hide, keep, deltas;
    
    hide = $(".hide");
    keep = $(".keep");
    
    // Get current positions
    deltas = [];
    keep.each(function(index) {
      deltas[index] = $(this).offset();
    });
    
    // Hide and query new position
    hide.hide();
    keep.each(function(index) {
      var pos = $(this).offset();
      deltas[index].left -= pos.left;
      deltas[index].top  -= pos.top;
    });
    
    // Show again, hide whilst keeping space, then animate
    hide.show().css("visibility", "hidden");
    keep.each(function(index) {
      $(this).animate({
        left: -deltas[index].left,
        top:  -deltas[index].top
      });
    });
    

    That’s completely un-optimised, and you probably want to do something when all the animations are complete, but it’s a start and that live copy does actually work.

    Re the bonus question: That part’s easy, just animate back to left: 0px / top: 0px.

    Here’s a version with a toggle, and adding in the fades (live copy):

    var hide, keep, deltas;
    
    // Get the spans
    hide = $(".hide");
    keep = $(".keep");
    
    // Showing or hiding?
    showing = !showing;
    if (showing) {
      // Showing, this is easy
      hide.css("visibility", "").hide().fadeIn();
      keep.animate({
        left: 0,
        top:  0
      });
    }
    else {
      // Hiding -- get current positions
      deltas = [];
      keep.each(function(index) {
        deltas[index] = $(this).offset();
      });
    
      // Hide and query new position
      hide.hide();
      keep.each(function(index) {
        var pos = $(this).offset();
        deltas[index].left -= pos.left;
        deltas[index].top  -= pos.top;
      });
    
      // Show again, hide whilst keeping space, then animate
      hide.show().fadeOut(function() {
        $(this).show().css("visibility", "hidden");
      });
      keep.each(function(index) {
        $(this).animate({
          left: -deltas[index].left,
          top:  -deltas[index].top
        });
      });
    }
    

    It’s more fun with more text.

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

Sidebar

Related Questions

My html code is: <div title=test class=xyz>Tesing</div> I want it to look like: <a
I have the following html code: <h3 id=headerid><span onclick=expandCollapse('headerid')>&uArr;</span>Header title</h3> I would like to
I have html code that looks roughly like this: <div id=id1> <div id=id2> <p>some
I have HTML code like this : <div> <a>Link A1</a> <a>Link A2</a> <a>Link A3</a>
The app consists of two activities: first - a listview with links to HTML
I have a HTML page that I have created that essentially consists of: <div>
I have made a web user control (.ascx) which consists of the two html
My HTML consists of lines of text(questions) and a button beside each to show/hide
html code meta tag description, it is generated dynamically and we have quotes in
My HTML code: <p>NEWS</p> <p> <form action=news.php method=post> <center><input name=NEW type=submit id=new value=NEW/> <input

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.