Create a dynamic animation of an image expanding and shifting towards the center of its parent container

Is it possible to animate an SVG image within a div to grow to 80% screen height and move to the center of the parent div when a specific function is called? If so, how can this be achieved?

function openNav(){
  $("#topnav").animate({height:'100%'})
  $("#title").fadeOut()
  //I want to add the image animation here
}

openNav();
@import url('https://fonts.googleapis.com/css2?family=Hind:wght@300;400&display=swap');
/* font-family: 'Hind', sans-serif; */

html, body {
  height: 100%;
  width: 100%;
  margin: 0px;
  background: rgb(229,239,243);
background: linear-gradient(0deg, rgba(229,239,243,1) 0%, rgba(181,232,255,1) 100%);
}

.topnav {
  background-color: #2541B2;
  border-bottom: 2px solid black;
  overflow: hidden;
  color: white;
  padding: 5px 5px 2px 12px;
  font-family: 'Hind', sans-serif;
  font-weight: 400;
  font-size: 30px;
}

#logo{
  height: 40px;
  float: left;
  margin-right: 5px;
}
<div id="topnav" class="topnav">
  <img src="https://svgshare.com/i/ifn.svg" id="logo">
  <span id="title">Website</span>
</div>
<script src="https://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="script.js"></script>

Answer №1

There are numerous methods to achieve this task. Here is one approach that utilizes the .animate() function. Take a look at the code snippet below.

$(function() {
  function openNav() {
    $("#topnav").animate({
      height: '100%'
    })
    $("#title").fadeOut();
    $("#logo").css("position", "absolute").animate({
      height: $(window).height() * .8,
      left: ($("#topnav").width() / 2) - ($("#logo").width() / 2)
    });
  }

  openNav();
});
@import url('https://fonts.googleapis.com/css2?family=Hind:wght@300;400&display=swap');

/* font-family: 'Hind', sans-serif; */

html,
body {
  height: 100%;
  width: 100%;
  margin: 0px;
  background: rgb(229, 239, 243);
  background: linear-gradient(0deg, rgba(229, 239, 243, 1) 0%, rgba(181, 232, 255, 1) 100%);
}

.topnav {
  background-color: #2541B2;
  border-bottom: 2px solid black;
  overflow: hidden;
  color: white;
  padding: 5px 5px 2px 12px;
  font-family: 'Hind', sans-serif;
  font-weight: 400;
  font-size: 30px;
}

#logo {
  height: 40px;
  float: left;
  margin-right: 5px;
}
<div id="topnav" class="topnav">
  <img src="https://svgshare.com/i/ifn.svg" id="logo">
  <span id="title">Website</span>
</div>
<script src="https://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="script.js"></script>

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

Misconception about the usage of jQuery's .each() function clarified with an illustrative example

Problem Description (See Fiddle): When clicking on the red boxes, they transform into kittens and display an alert with the current value of i. Clicking on a large fading kitten will reset everything. I am puzzled as to why alert(i) is triggering multipl ...

How can I import the raw JSON data from a table into a pandas DataFrame?

I am attempting to extract the JSON data and convert it into a dataframe from: "" , which is the original data displayed in a table at the bottom of this page "" The content on the JSON page seems to be basic JSON data like"[{\"SECURITYCODE\":& ...

Why is my AngularJS application triggering two events with a single click?

<button id="voterListSearchButton" class="serachButton" ng-click="onSearchButton1Click()">find</button> This button allows users to search for specific information: $scope.onSearchButton1Click = function() { var partId = $("#partIdSearch" ...

Generating elements added at various depths within an HTML document with the help of JavaScript

create_new.append("div") .append("form").merge(update_5) .attr("action", d => d.market) .attr("target","_blank") .style("width","100%") .style("height","282") .append("input").merge(update_5) .attr("type","submit") ...

The JavaScript React Slider fails to hide the next arrow button when there are no images displayed on the screen

What I am trying to achieve is the display of a certain number of images inside a div according to the screen size. Currently, I have managed to hide the previous button when currentIndex != 0. However, I am facing difficulty in hiding the next button when ...

Firestore TimeStamp.fromDate is not based on UTC timing

Does anyone have a solution for persisting UTC Timestamps in Firestore? In my Angular application, when I convert today's date to a Timestamp using the code below, it stores as UTC+2 (due to summer time in Switzerland). import {firebase} from ' ...

Styling GeoJSON data in the React Leaflet mapping library can greatly enhance the

I successfully incorporated the leaflet map library into my react project. You can check it out here. I also created a geojson map component as shown below: class MapContainer extends React.Component { state = { greenIcon: { lat: 8.3114, ...

What is the best way to change an int32 to a float32 in Deeplearn.js?

In December 2017, this code did the job perfectly. However, after updating Deeplearn.js to the latest version, it no longer functions as expected: math.scope(function(keep, track) { var i = track(dl.Array3D.fromPixels(rawImageData, 4)); i = math.multi ...

Unable to create a new collection in Firebase Firestore

I encountered an issue while trying to add a collection in Firebase Firestore using the function .collection(doc).set. Despite finding the new user in authentication in Firebase, the collection was not created and the console displayed an error message. ...

Bootstrap 4 allows for the use of the d-lg-flex class to create a flexible column layout

I'm facing an issue with my table on smaller screens where some columns need to be hidden. Here's the code snippet I'm using: <table> <tr> <td>Normal 1</td> <td class="d-lg-flex d-none">hidden 1</t ...

Struggling to align a search box with other items in a custom navbar using Bootstrap 4?

I created a unique navigation bar using Bootstrap 4's grid system. The navbar is designed with two sections: one for the navigation items on the left and another for the search box on the right. Unfortunately, I am facing an issue where the search box ...

Modify the shading of the mesh generated with the face3 method

I have utilized face 3 and three js to generate a mesh, but the expected color is not displaying correctly on the mesh. Below is the code snippet I used: var geometry = new THREE.Geometry(); var f = 0; for (var i = 0; i < data.real.length ...

Arrange the items in a list in JavaScript in descending sequence

How to sort a list of records in JavaScript in descending order? var number; //dynamic number retrieved from API var test; //dynamic text retrieved from API for (var i; i <= accList.length; i++) { var odlist = 'you have :' + test + number ...

Error with Chakra UI and React Hook Form mismatched data types

Struggling with creating a form using ChakraUI and React-Hook-Form in TypeScript. The errors seem to be related to TypeScript issues. I simply copied and pasted this code from the template provided on Chakra's website. Here is the snippet: import { ...

Adding app stylesheet in Django

I'm a bit unsure about how to incorporate CSS into my HTML. I have an app within my project that has its own template folder, and I would like to include the sample.css file in my HTML. I think it should be something like this: <link rel="styleshe ...

What is the best way to ensure that the value of a <textarea> in jQuery is consistently saved and reflected in the HTML document?

I have a function on my website that allows users to input text which is then displayed on the page. However, this text disappears when the page is reloaded and does not stay permanently. How can I use jQuery to make sure that the entered text remains on ...

Turned off jquery on a specific div in order to resolve compatibility problems with Vue.js

Currently, I am working on a Drupal project which includes JQuery in all pages. We have recently introduced Vue.js for creating dynamic components directly in the HTML pages (not for building a single-page application). However, we are facing an issue whe ...

After a successful login, learn how to implement a bottom tab menu in React Native

I'm diving into the world of react-native and finding myself a bit lost when it comes to routing and navigation. I have 4 screens - Login, Register, Home, and Links. The Register and Login screens are all set up, with the ability to navigate back usin ...

I often find myself frustrated while using Next.js because the console automatically clears itself, making it difficult for me

I am facing an issue with my form in the Next.js app. Here is how it is defined: <form onSubmit = { async() => await getCertificate(id) .then(resp => resp.json()) .then(data => console.log(data)) }> Whenever there is an erro ...

Show the value of a JavaScript object in VueJS

New to Vue and need some guidance... I'm having trouble accessing the values in a JS object displayed in the DevTools within one of my routes in a Vue app. Specifically, how can I display the values from filteredData:Array[1]? https://i.sstatic.net/ ...