Guide to animate/move a tile to a specified location using CSS at 90x90px dimensions

I am trying to achieve a smooth transition for grid[row1][col1] sliding over to grid[row2][col2], followed by an expansion to 90x90px

Does anyone have any suggestions on how to accomplish this?

Here is an example of the styling:

<style type="text/css">
      #grid {
        background-color: #ccc0b3;
        width: 400px;
        height: 400px;
        position: relative;
        border-radius: 5px;
      }

      .box {
        width: 80px;
        height: 80px;
        border-radius: 5px;
        font-family: Arial, sans-serif;
        font-size: 35px;
        font-weight: bold;
        display: inline-block;
        position: absolute;
        padding: 5px;
        margin: 5px;
        text-align: center;
        line-height: 80px;
      }
    </style>

Javascript function for creating the class named box:

function makeNew(row, col) {
      var number = Math.random() < 0.9 ? 2 : 4;
      var color = pikColor(number);
      var textcolor = textColor(number);

      return grid[row][col] = $('<div>')
        .css({
          background: color,
          color: "blue",
          top  : row * 100 + 'px',
          left : col * 100 + 'px'
        })
        .text(number)
        .addClass('box')
        .appendTo($('#grid'));
    }

Function for updating grid[row2][col2] with the value from grid[row1][col1]:

function merge(row1, col1, row2, col2) {
      if (merging[row2][col2]) {
        return false;
      }

      grid[row2][col2].remove();
      grid[row2][col2] = grid[row1][col1];
      grid[row1][col1] = null;
      var number = grid[row2][col2].text() * 2 ;
      var color = pikColor(number);
      var textcolor = textColor(number);
      alert(number);
      alert(textcolor);
      merging[row2][col2] = true;

      grid[row2][col2]
        .css({
          background: color,
          color: textcolor,
          top  : row2 * 100 + 'px',
          left : col2 * 100 + 'px'
        })
        .text(number);

      return true;
    }

Thanks in advance!

Answer №1

To accomplish this task, I recommend utilizing the Jquery .animate function. Here's a sample code snippet:

grid[row1][col1].animate({ top: row2 * 100, left: col2 * 100, width: 90, height: 90 },
    { duration: 1000 })

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

Managing both TCP/IP raw requests and HTTP requests on a single server requires careful configuration and resource allocation

I have developed a GPS tracking system and implemented a server using Node.js. Below is the code snippet for reference. const net = require('net'); const lora_packet = require('lora-packet'); const dataParser = require('./dataPars ...

What is the best way to combine Bootstrap and custom CSS, specifically the home.module.css file, in a React project?

I'm currently experimenting with utilizing multiple classes to achieve an elevated button effect and a fade animation on a bootstrap card. Here's the code snippet I've been working on: import Head from 'next/head' impo ...

Interactive Button Animation using Three.js

After importing a Mesh element into three.js from an fbx file, I am looking to enhance it with an effect similar to that of a clickable button. I am aiming to achieve the same pushable button effect as demonstrated in the first button style found on http ...

The reason why the div appears below the image

Is there a way to position the div above the image rather than below it, even when setting the z-index attribute in the code? The current code structure is as follows: <main id="content" role="main"> <div style="text-align: center"> & ...

Is there a way to retrieve a particular object from the state and access one of its elements?

I have a component called Tweets.js: import React, {Component} from "react"; export default class Tweets extends Component { constructor(props) { super(props); this.state = {tweets: [], users: []}; } componentDi ...

Having trouble with lazy loading javascript. I've tried following the instructions but nothing seems to be working. Feeling

Check out this link for some amazing drop ceiling designs! I'm facing a challenge with having 10,000 images on my page and I think Lazy Load could be the solution. Is there a way to implement it effectively or am I overlooking something simple? ...

Tips for refreshing views with Angular JS

I am looking to refresh all the views displayed on my page. The layout consists of a Header, Footer, and Body view. Within the Header view, there is a dropdown menu where users can choose their preferred language. Upon selecting a language, I want all the ...

Can combinators be applied to select elements containing options?

How can I use a select dropdown menu to toggle the appearance of a text input field? Specifically, when the option with a value of '4' is chosen, the text input should become visible. Here is the code snippet: HTML <div class="paren ...

Error: Unable to retrieve REACT JS due to a Type Mismatch

As I develop my application, I encountered an issue while attempting to sign up a user with a correct email address such as [email protected]. It resulted in a TypeError: Failed to fetch. Strangely, when I input an invalid email like "user", the proce ...

Function for jQuery dropdown panels

I am currently facing an issue with my dropdownpanel function for a data table. The problem is that the function only seems to work on the first button. I am trying to toggle the panel by adding and removing the "visible" class. Can anyone help me troubles ...

Can we integrate the Node.js API into Meteor?

Being new to Meteor.js, I've been wondering if it's possible to utilize the node API in my project. I've hit a roadblock and haven't been able to find any information on this topic despite spending a significant amount of time researchi ...

Retrieving the body of a GET request using NodeJS and axios

Let me share my request with you: axios.get(BASE_URI + '/birds/random', {Stuff: "STUFF"}) .then(randBird=>{ const birdData = randBird.data const bird = { age: birdData.age, ...

I'm struggling with an issue of being undefined in my React.js project

This code snippet is from my app.js file import React, { useState, useEffect } from "react"; import { v4 as uuid } from "uuid"; import "./App.css"; import Header from "./Header"; import AddContact from "./AddCo ...

Auto-scrolling text box cursor movement

My query is quite similar to the topic discussed in this thread on automatic newline in textarea. However, my situation involves multiple textareas with a 1-row attribute, making it seem like writing on air due to the absence of visible borders (I've ...

Switch between CSS and jQuery styling

Here is a code snippet I'm using to toggle the visibility of content: $(function(){ $('#slider').css('display',''); $('#hideslider').click(function(){ $('#slider').slideToggle('slow&apos ...

What is the process for loading this image?

While browsing through this stunning website, I came across a feature that caught my eye. Can someone please explain how the designer displayed the "The magic is loading" effect: The image vanishes once the site has finished loading completely. ...

Minimum width compared to Maximum Width

Exploring media queries for the first time and seeking some guidance. I initially developed a Desktop version of my website, now considering making it responsive as well. While researching, I came across suggestions to use max-width in this scenario, but ...

Implementing jQuery getScript in a Ruby on Rails 3 application

After watching a railscast tutorial on loading records through ajax when a link is clicked, I implemented the following javascript: $(function() { $("#dash_container th a").live("click", function() { $.getScript(this.href); return false; }); } ...

Calculate the total number of seconds from an ISO8601 duration with TypeScript by utilizing the date-fns library

Given an ISO8601 duration string like "PT1M14S," I am looking to convert it to seconds as an Integer using the date-fns library in TypeScript. ...

Error: Unhandled promise rejection: [object Boolean]

I am encountering an issue while trying to secure a route in my Angular application. Despite what I believe to be the correct implementation, I am facing an error message when the negative scenario is triggered: ERROR Error: Uncaught (in promise): [object ...