Using JQuery to update text by sliding in the new one and pushing down the old text

I am experimenting with JQuery to create a unique effect where new text pushes the old text down and causes it to vanish. Essentially, it is a stylish text replacement: the new text displaces the old text while making it disappear.

Someone has developed something similar on this JSFiddle.

var slider = $("#slider");
  $("#button").on('click', function(){
  slider.slideUp(1500, function(){        
    slider.html("been changed").slideDown(1500);                        
  });
});

However, the provided solution does the reverse. It slides up and makes the previous text disappear. Reversing the methods does not yield the desired result. Is there an alternative approach to accomplish what I intend to do?

Answer №1

Take a look at this.

var slider = $("#slider");
var slider2 = $("#slider2");
$("#button").on('click', function(){
slider2.html("been changed");
slider2.slideDown(1500, function(){
     slider.css("display","none");
});

});
#slider {
border: 3px green solid;
width: 200px;
height: 200px;    
}
#slider2 {
border: 3px green solid;
width: 200px;
height: 200px;
display:none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="slider2">
</div>
<div id="slider">
    should change
</div>
<button id="button">Click me!</button>

I hope this aligns with your expectations. :-)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to send a prop for inline styling in a React component that contains an array of data?

My ShowData component is responsible for rendering in both my App.js and index.js files. import React from "react"; import SwatchData from "./SwatchData"; import { DataTestContainer } from "./DataTestContainer"; function ShowData(props) { const DataCom ...

Utilizing a promise instead of making a jQuery ajax request

A scenario I am facing involves a function that is set to execute jquery.ajax and return it as a promise for future processing. However, in certain cases, the function possesses enough information to proceed synchronously without triggering the ajax call. ...

Steps for showcasing the data entered in the input box

I am looking to enhance my skills in working with Angular and JavaScript. I would greatly appreciate any feedback on the issue I am facing here. My goal is for the text box input to display: "hello {name} , would you like to play a game? However, curr ...

Repositioning with Flexbox: shifting the middle element to a new line

I have a flex item that contains three divs. ┌────────────────────────────────────────┐ | WRAPPER | | ┌─────────┬─ ...

Creating a hierarchical structure for the Category Model in Sequelize using self-referencing

My database has a Category Table that uses a "parent" column: +----+--------------+--------+ | id | name | parent | +----+--------------+--------+ | 1 | Service | null | | 2 | Lifestyle | null | | 3 | Food & Drink | 2 | | ...

Designing a user-friendly search form using HTML

As a beginner in coding, I am attempting to set up a search form using basic HTML on a webpage. Unfortunately, I am facing difficulties in processing the results properly due to my limited understanding of certain terms. Here is my desired outcome: http: ...

Utilizing multiple class names in Material UI with identical definitions

When working with traditional CSS, it is common to define shared properties between classes like this: .classA,.classB{ background-color: black; } In Material UI and using theming, the equivalent would be: styles = (theme)=>({ classA:{ ba ...

Jest.config not allowing exclusion of specific files

I am having trouble excluding all index files from coverage, specifically the src/index.jsx and src/reportWebVitals.js files. Even though I added them to my ignore patterns, the covered lines still appear in my coverage report. Check out my Github repo on ...

Measuring Bootstrap's breakpoints using specific divs: A beginner's guide

Is it possible for Bootstrap 5 to create responsive layouts with draggable vertical borders between two columns? The answer is Yes, by adjusting Bootstrap to use container queries instead of media queries. Major browsers have supported container queries si ...

Looking for assistance in determining a solution for progress bar implementation

Currently, I am developing a simple application using web technologies like HTML, CSS, and jQuery Mobile. This app enables me to create goals and save them to a listview using the <li> element. Every <li> representing a goal will have an assoc ...

Take away the follow option on the embedded tweet

I need to customize the appearance of embedded tweets on a website by removing the follow button as well as the reply, favorite, and retweet buttons in the footer. Here is a simple HTML example: <blockquote class="twitter-tweet"> <a href="htt ...

Terminate or flag an AJAX request upon receiving a 200 OK response from the browser

My request is as follows: // =============================================== start() // // clicked_button : the user click the start button. // app_path : the app path // // return none. // var start = function(clicked_button, app_path) { $.aja ...

Navigating and organizing with React Native: TabBarIOS and Navigation

I have a basic app that consists of 3 tabs. The tabs are set using TabBarIOS in the index.ios file. I am not utilizing Navigator or NavigatorIOS. In each TabBarItem, I directly include the component name within tags. Here is an example: return( &l ...

Retrieving the value of an object based on a dynamic key in Typescript

Currently, I am facing an issue with exporting a single value from a configuration object based on the process.env.NODE_ENV variable. Specifically, I am attempting to retrieve the value of the configEnvs variable like this: configEnvs['local']. H ...

Utilizing variable values in HTML and CSS to enhance a website's functionality

My current project involves modifying an HTML web resource for use in Dynamics 365. I need to replace a static URL with a dynamic value obtained via Javascript, specifically: var URL = Xrm.Page.context.getClientUrl(); There are multiple instances within ...

Difficulty arises with AJAX GET function within PHP FUNCTION

In my JavaScript code inside profile.php, I have a while loop that contains another while loop which I only want to run after a button click. Here's the JavaScript code: $('.commentbtn').click(function() { $.ajax({ url: 'i ...

Utilizing Next.js routing to accommodate two distinct subdomains on a single website

I am looking to develop a new platform using Next.js (React.js and React-router). The platform will have two distinct spaces - one for users and another for the owner to manage all users. To achieve this, I plan on splitting both areas into two subdomains: ...

Alter the texture or hue in the mesh surface

I am faced with a challenge involving a Three.Geometry object that contains multiple vertices and faces forming a grid. My goal is to dynamically alter the color or material of a selected face. geometry.colorsNeedUpdate = true; geometry.faces[1].color.se ...

Tips for Ensuring the Longevity of my Node.js Server

After developing an application in Node js with express js, I am facing an issue where the server shuts down whenever I close the command prompt. To start the app, I use the following command: c:/myApp > npm start I attempted to resolve this problem b ...

What could be the reason for this script not functioning properly and...?

Here is some HTML code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" conte ...