Issue with CSS and JavaScript: content is not properly centered after animation

Hey everyone, I'm doing my best to figure out the correct animation for this project. It seems like the issue might be in the JavaScript code, but I'm not entirely sure.

https://i.sstatic.net/4FPd2.jpg

The movie poster should load up in the center, but right now it's loading up in the corner instead.

https://i.sstatic.net/AP1FP.png

When you click on a poster, it should look like this:

https://i.sstatic.net/vfuvu.png

Feel free to check out the codepen link for reference!

var $play = $('.play'),
$detail   = $('.detail'),
$movie    = $('.movie', $detail),
$close    = $('.close');

$('.movies .movie').click(function(){
  $movie.html($(this).html());
  $play.appendTo($movie);
  $poster = $('.poster', this).addClass('active');

    console.log("===debug===============");
    console.log("top: " + $poster.position().top);
    console.log("left: " + $poster.position().left);
    console.log("width: " + $poster.width());
    console.log("height: " + $poster.height());
    
  $('.poster', $detail).css({
    top: $poster.position().top,
    left: $poster.position().left,
    width: $poster.width(),
    height: $poster.height()
  }).data({
    top: $poster.position().top,
    left: $poster.position().left,
    width: $poster.width(),
    height: $poster.height()
  })

  $detail.show();

  $('.poster', $detail).delay(10).queue(function(next) {
    $detail.addClass('ready');
    next();
  }).delay(100).queue(function(next){
    $(this).css({
      top: '-10%',
      left: '-6%',
      width: 266,
      height: 400
    });
    next();
  })
})

function close(){
  console.log('asd');
  $p = $('.detail .poster');
  console.log($p)
  $p.css({
    top: $p.data('top'),
    left: $p.data('left'),
    width: $p.data('width'),
    height: $p.data('height'),
  })
  $detail.removeClass('ready').delay(500).queue(function(next){
    $(this).hide();
    $poster.removeClass('active');
    next();
  });
}

$('body').click(function(e){
  $p = $(e.target).parents();
  
  if ($p.is('.app')){
    return false;
  } else {
    close();
  }
})

I would really appreciate any assistance with this! Thanks in advance!

Answer №1

To update the CSS file, switch the position property from absolute to relative in the following code snippet:

.information .thumbnail { 
  position: relative;
......
...
}

Answer №2

Adjust the poster's position to relative and utilize display and float properties accordingly.

Please review the revised version.

CodePen link

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

JavaScript in IE/Edge may not run correctly if it is loaded from the cache

I am facing a peculiar problem with Internet Explorer (IE) and Edge. Upon initially loading a page, everything functions perfectly fine. However, if I navigate away from the page to another page on the same website, JavaScript errors start showing up on th ...

Is there a way to retrieve a variable within an if statement?

A question I have is related to a registration form where I use AJAX response onkeyup to check if the username or email already exists in my database. The code snippet for this validation process looks like this: $query = $_GET['query']; $fiel ...

Choose elements with unique identifiers other than those provided by the API

Seeking assistance with Material UI select element and naming dropdown. Have a few questions: 1: My API that populates the dropdown lacks good names. Is it possible to assign names like 'data 1, data 2, data 3...' to the options without manually ...

Issue with Foundation6 popup form: Unwanted loss of focus on field when revealed (possibly due to jQuery

While developing a popup form using Foundation6 reveal, I encountered a JavaScript issue that seems to be related to event binding or handling in jQuery.js / Foundation.js. https://i.stack.imgur.com/MIWUS.png When I click on any field within the reveal w ...

Using AJAX to load a PHP file in CodeIgniter is a great way to

I'm a beginner in the world of web development and I need help with loading my PHP file containing HTML content to update the span element. My framework of choice is CodeIgniter. Every time I try, I encounter an error. Below is my JavaScript code: ...

The FreeTextBox Editor suddenly stopped functioning after the jquery post method was used

Thank you in advance. I have been utilizing the FreeTextBox editor within my asp.net web application, and it has been functioning well. I use a jquery Post method to populate the editor as well as other form fields with values retrieved from the database. ...

Is it possible for the sum to turn into NaN in Bootstrap Table JavaScript?

I used bootstrap to create a table that links with phpmyadmin. I need to show the total current amount in the table, which should update when using the search function. However, I keep getting NaN as my result. Below is the relevant code: // PART OF CODE ...

Can I modify individual properties of xAxis.labels in HighCharts?

I am seeking to customize the properties of my labels on the x-axis in a unique way (View my query here). I have a clear understanding of how to achieve this for dataLabels: See API reference. This process is akin to what has been explained here. Howeve ...

Tips for integrating Tornado authentication with AngularJS

I have been experimenting with the authentication system outlined in the tornado documentation, and I am encountering a Cross-Origin Request issue when trying to integrate it with AngularJS. Is there a way to successfully combine Tornado's authentica ...

Using React JavaScript to access an Axios API and retrieve a surf object array in JSON format

When using Axios to call an example API in React, my goal was to render a specific field from the array. For instance, I wanted to display only the company name of the first person in the output - "person[0].company.name". However, instead of getting "Roma ...

Issue with AngularJs variable not appearing in the view

Whenever I try to utilize the variable "navitem.route" as a parameter in a function, it doesn't show up in the view as expected. Instead of displaying the value of the variable, the generated HTML shows "navitem.route". However, when used within curly ...

Achieve smooth scaling of font size in CSS according to body width without the need for JavaScript

Can the font size be smoothly scaled in relation to the width of the body or parent element? I am seeking a solution that does not involve javascript. Is it feasible to relate rem to a specific width? ...

Prevent the appearance of a scrollbar on a fixed-position popup element

Whenever I click on a button, a Sidebar opens up and fills the entire screen due to its position being set to fixed. Here's how it looks with TailwindCSS: return ( <div className="fixed z-40 flex left-0 top-0 h-screen w-screen"> ...

Creating an instance without assigning a value to a variable in the constructor declaration

I am interested in developing a Node REST API using Typescript and have started by creating a basic class to manage the Express application. import express from 'express'; import { Server } from 'http'; import { injectable } from &apos ...

Adhesive Navigation Bar

Check out this link: JSFIDDLE $('.main-menu').addClass('fixed'); Why does the fixed element flicker when the fixed class is applied? ...

Creating a live data stream to listen for new additions to the database in PHP/CodeIgniter

I have implemented a code using ajax to fetch data from a MySQL database in real-time. Currently, the ajax call retrieves all the data and then loops through each entry to display it. What I am looking for is a way to avoid fetching all the data again and ...

Is there a way to access the directory of $object[""0""].projhours in AngularJS without triggering any syntax errors?

Being new to this, I am trying to retrieve the value of projhours from this directory in console.log() without encountering a syntax error. While right-clicking on the projhours directory in the Chrome console displays ($object[""0""].projhours), AngularJS ...

Add a Vue component dynamically before another component within a v-for loop

Seeking advice on how to incorporate an unread component before a dynamic message component within a v-for loop. The goal is to display an unread panel before any unread messages, indicating their status clearly. Below is the sample code without the unrea ...

Utilize a single CDN or multiple CDNs to access and retrieve files

When I visit a standard webpage, I usually load the following resources from various CDNs: jQuery Angular Bootstrap Icomoon several Angular plugins Would it be more efficient to load all these resources from a single CDN, or is it fine to use multiple ...

The three.js library is throwing an error because it is unable to access the 'geometry' property of an

function CreateNewSphere(x, z) { var sphereGeometry = new THREE.SphereBufferGeometry(10 * factor, 32, 32); var sphereMaterial = new THREE.MeshBasicMaterial({ color: SphereColor, wireframe: false }); var sphere = new THRE ...