Triggering animation with jQuery and CSS

I am working on a one-page site and I want to make a parallelogram disappear when a button is clicked for the next part. Currently, it is disappearing from right to left but I would like to change the direction to left to right. Additionally, I have a similar animation for height that hides the box.

$(document).ready(function() {
  $("a.article").click(function() {
    var para = $("#parallelogram");
    para.animate({
      width: '0px'
    }, "slow");
  });
});
#parallelogram {
  width: 600px;
  height: 400px;
  background: white;
  -webkit-transform: skew(-20deg);
  -moz-transform: skew(-20deg);
  -o-transform: skew(-20deg);
  position: relative;
  top: 200px;
  left: 430px;
  -webkit-transition: width 1s;
  /* For Safari 3.1 to 6.0 */
  transition: width 1s;
}
#parallelogram:active {
  width: 0px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<nav>
  <ul>
    <li><a class="article" href="#article">Article</a>
    </li>
  </ul>
</nav>


<div class="page" id="content">
  <div id="parallelogram">

  </div>
</div>

Is there a way to change the animation direction to go from left to right instead?

P.S. I am new to JQuery

Answer №1

Ready to solve your JavaScript problem

JavaScript Solution

$(function(){
 $('.article').click(function(){
   var para = $("#parallelogram");
   para.animate({
        width: '0px'
    }, "slow");
 })
})

View Demo

Answer №2

Give this shorter code a try based on your current implementation:

$(function(){
$('.article').click(function(){  
$("#parallelogram").animate({
    width: '0px'
}, "slow");
 })
 }

If you want to move left or right, check out the following fiddle and make it your own:

View Demo on Fiddle

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

Why is the image cut in half on mobile devices but displaying correctly on computer screens? Could it be an issue with

There seems to be an issue on mobile screens that does not occur on computer screens. When the user clicks on the image, it disappears, and when they click another button, it reappears. However, there is a problem with how the image appears - it is cut off ...

utilizing an arrow function in the same manner as a traditional function

I am a fan of the new arrow ()=>{} syntax and would love to use it wherever possible. I understand that arrow functions point to the outer this context. Is there a way to modify an arrow function so that "this" points to its inner scope? For example, h ...

Error: Uncaught TypeError - Unable to access the 'handleClick' property of undefined within a forEach loop

I came across the following code snippet articles_list.jsx import React from 'react'; import './articles_list.css'; export default class ArticlesList extends React.Component { constructor(props) { super(props); this.state ...

Difficulties with integrating tooltips into SVGs

Being a minimalist, I am facing restrictions while working on a website. I desire interactive tooltips to appear when users hover over specific sections of my SVG. However, I also want to incorporate this interactivity within the SVG itself. The challenge ...

Is there a way to eliminate the additional and varying pseudo-padding on text inputs in both Webkit and Gecko browsers?

The issue I'm facing is specific to input[type="text"] elements in Webkit. No matter what adjustments I make, it seems like there is an additional padding: 1px 0 0 1px (top and left only) applied to the element. A similar anomaly occurs in Gecko as w ...

Show a picture outside of the dropdown container

I'm currently navigating the world of web development and I'm facing a challenge with getting an image to display outside of a dropdown div. Despite numerous attempts at setting the image's position to relative, with overflow-visible, I have ...

What is the best way to fetch values from individual buttons using PHP?

<form action="posts-ayarlar.php" method="POST" id="demo-form2" data-parsley-validate class="form-horizontal form-label-left"> <table class="table table-striped table-bordered" ...

Achieving Perfect Alignment of Images Using HTML and CSS

I am currently working on designing a HTML/CSS layout for a Kiosk-style website. However, I am encountering some challenges in getting the alignment of images and text to appear exactly as desired. The goal is to have the logo and header remain fixed in ...

What could be causing errors with my kick command?

Hey everyone, I'm currently working on implementing some admin commands. Right now, I'm focusing on creating a kick command, but I keep running into errors. Making any changes seems to cause issues in other parts of the code. This is where I&apo ...

Encountering an error stating that $.browser is undefined within a jQuery UI script

Before reaching out for help, I want to clarify that I did not ask this question without attempting to find a solution first. I understand that there are numerous discussions on this topic on various platforms like SO and the internet. However, everyone se ...

How can I convert ajax response into an array?

When adding data to a database, a new ID is needed for each element. The element's ID is passed into the ajax data... $( ".silly-string" ).draggable({ containment: '#_moon_static_bg_status', stop: function(event, ui) { ...

A guide on activating Effect in Div using just css

I have tried all the questions and answers related to this topic. Additionally, I attempted to solve related questions but was not successful. Please read my question thoroughly. What I Want: When I click on the click me Div, the second hiddendiv Div i ...

There seems to be an issue with AppModule in your code. The error message states that it is not recognized as an NgModule and the problem

After upgrading to node 6, angular 4, typescript 2.3.2, and @angular/cli 1.02, I meticulously followed the steps outlined in the Guide for updating @angular/cli. I will include my entire package.json below in case there are any relevant details. The specif ...

Switching Over to Burger Menu

I created a burger menu using HTML, CSS, and jQuery that switches from a full-width menu to a burger menu. However, I'm facing an issue with toggling the dropdown when the menu collapses. Here's my code: <!DOCTYPE html> <html> < ...

Display real-time information fetched from sessionStorage (in JSON format) on a Listview widget

In my session, I have the following JSON data stored: Prescription: [{"medID":"id1","medName":"name1","medQty":"qty1","medDirec":"Directions1"}, {"medID":"id2","medName":"name2","medQty":"qty2","medDirec":"Directions2"}] I am looking to automatically dis ...

What is the best way to transfer an array from an Express Server to an AJAX response?

My AJAX request successfully communicates with the server and receives a response that looks like this: [{name: 'example1'}, {name: 'example2'}] The issue arises when the response is passed to the client-side JavaScript code - it is t ...

Angular is unable to fetch the chosen option from a dropdown selection

Recently, I encountered an issue with a module form that appears as a pop-up. Within this form, users can input data required to create a new object of a specific class. One field allows users to select a ventilation zone for the new room object being crea ...

Verify and deselect boxes

Can someone help me with checking and unchecking checkboxes? I'm facing a lot of issues with it. You can find my code snippet here: http://jsfiddle.net/N5Swt/: <input type="checkbox" id="checkbox1" /> <span> Check me! </span> // ...

Troubleshooting the Hover Effect of Buttons in Next.js when Using Tailwind CSS for Dynamic Color Changes

Encountering a problem with button hover functionality in a Next.js component using Tailwind CSS. The objective is to alter the button's background color dynamically on hover based on a color value stored in the component's state. This code func ...

Exploring the World with AngularJS and Google Maps API through ngGeolocation

Having some difficulty displaying my geolocation on Google Maps API using a marker. I am utilizing the ng controller ngGeolocation and the http://angular-ui.github.io/angular-google-maps/ Previously, I hardcoded the marker and map location without any is ...