Connect CSS Transition to a click action

Below is the code snippet. When you click on the div, it creates a folding effect to the left. You can view it here.

I want to link this effect to the arrows I use for sliding back and forth.

For example:

  • The left arrow should move the slide to the left and trigger the fold effect to the right

  • The right arrow should do the opposite

Here are my arrows:

  <nav class="slides-navigation">
    <a class="next" href="#">
      <i class="fa fa-arrow-circle-o-right fa-5x"></i>
    </a>
    <a class="prev" href="#">
      <i class="fa fa-arrow-circle-o-left fa-5x"></i>
    </a>
  </nav>

and CSS for the current div effect:

body {
perspective: 4000px; /* Don't forget vendor prefixes */
-webkit-perspective: 4000px;
}

.transit {
  transition: transform 1s;
  transform-origin: left;
  -webkit-transition: -webkit-transform 1s;
  -webkit-transform-origin: left;
}

.transit:active {
  transform: rotateY(90deg);
  -webkit-transform: rotateY(90deg);
}

Update:

I thought I was getting close, but no luck.

I attempted to add the "transit" class using an addClass function:

$(".next").click( function() { 
  $("#slide").addClass("transit")
 });

It does work, however the slide transitions too quickly to see the effect. And when you return, the div remains stuck in the transition state.

Answer №1

For those interested in using jQuery, here is a helpful JSFiddle link

CSS:

body {
    perspective: 1000px;
    -webkit-perspective: 1000px;
}
div.transit {
    background-color: #ccc;
    width: 300px;
    transition: transform 1s;
    transform-origin: left;
    -webkit-transition: -webkit-transform 1s;
    -webkit-transform-origin: left;
}

/* Adding the transition effect to an active class */
div.transit.active {
    transform: rotateY(90deg);
    -webkit-transform: rotateY(90deg);
}

HTML:

<div class="left-Slide">
    <div class="transit">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse feugiat lectus in lectus posuere, et tempus nunc euismod. Vivamus ut velit malesuada, dictum lectus vitae, fringilla risus. Nam facilisis magna eget quam imperdiet placerat non non nunc. Etiam eget lacus sem. Donec a neque tempor, cursus sem quis, porttitor elit. In in diam volutpat, pharetra ipsum lobortis, aliquet purus. Praesent odio risus, feugiat eget quam et, placerat interdum quam.

    </div>
</div>

<!-- INSERT YOUR ARROWS HERE -->
<nav class="slides-navigation">
    <a class="next" href="#">
        <i class="fa fa-arrow-circle-o-right fa-5x"></i>
    </a>
    <a class="prev" href="#">
        <i class="fa fa-arrow-circle-o-left fa-5x"></i>
    </a>
</nav>

JS:

// Connecting CSS effect to arrow clicks
$('a.next').click(function() {
    $('div.transit').addClass('active');
});

$('a.prev').click(function() {
    $('div.transit').removeClass('active');
});

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

The kendo-grid-messages are utilized across all columns

I encountered an issue while working with the following code: <kendo-grid-column field="isActive" [title]="l('Status')" filter="boolean"> <kendo-grid-messages filterIsTrue="Yes" filterIsFalse=&qu ...

How can I handle moving to button code-behind when validation fails without relying on Page.IsValid?

Recently, I encountered a challenge with an ASP.NET page that contains both ASP.NET validators and JavaScript checks. As I delved into the button code behind the scenes: protected void Button2_Click(object sender, EventArgs e) { if (Page.IsVal ...

Tips for keeping a label above an input field

Is it possible to add a styled label on top of an input element? I have seen images placed inside input elements for indicating the type of input accepted. For example, in a login form, a user icon represents the username field and a key icon represents th ...

In need of assistance with filtering lists using JQuery

Hi there! I'm looking to modify a list filtering function by targeting multiple ul tags within the same div instead of just filtering li elements. Any ideas on how this can be achieved? Below is my JavaScript code: $( document ).ready(function() { ...

A comprehensive guide on utilizing the ngFor directive for looping through objects

After trying to iterate over this dataset within my HTML, I attempted a nested ngfor, but unfortunately encountered an error. My attempt involved iterating the object twice with a nested ngfor, resulting in the following error: HabitRecordsComponent.ht ...

Bypass the save as dialogue box and initiate automatic file download without interruption

Working on an Angular 1 web application, I am utilizing the HTML download Attribute. Using the code snippet below: <a href="/images/myw3schoolsimage.jpg" download>, I am enabling users to download presented data as an Excel spreadsheet. My goal i ...

Having trouble resolving errors encountered while running the `npm run build` command, not sure of the steps to rectify

I am currently working on my first app and attempting to deploy it for the first time. However, I have encountered an error that I am unsure of how to resolve. When running "npm run build", I receive the following: PS C:\Users\julyj\Desktop& ...

Unable to animate a second click using jQuery/CSS

I'm having an issue with animating on click using CSS. The animation works fine on the first click, but it doesn't work on the second click. This is because the click event is being overridden by jQuery to enable the dropdown menu to open onClick ...

I'm having trouble retrieving and rendering data in HTML using AngularJS and Spring

After fetching the data, I am unable to see it in the HTML code. The web browser console displays the JSON data but it is not visible in the HTML code. Here is my AngularJS code: $scope.refresh = function(){ fetchData(); }; $scope.fetchData = functio ...

Integrate a resizable sidebar on the webpage's right side that dynamically adjusts the layout

As I develop a Chrome Extension, my goal is to incorporate a sidebar into all webpages without overlapping the existing content. The sidebar should be placed beside the content, effectively reducing the width of the body of the webpage to the initial width ...

unable to update the table due to issues with the knockout observableArray

My goal is to collect values from form fields and store them as an object in an observableArray. I want to display these objects in a table so that every time I hit the 'add' button, the table should be updated. However, I am facing issues with t ...

Ways to incorporate line spacing using CSS

Is there a way to adjust the spacing between the drop down boxes in the sidebar so that they align neatly with the questions in my section? select { font-family: 'Courier New', monospace; color: black; font-weight: bold; font-size: 3 ...

Ensure that the text fits by squishing it in the JLabel

How can I make JLabel text fit in a constrained space (JTable) by only horizontal squishing when the text is too long and gets truncated? Take a look at the upper JLabel in these examples: https://i.stack.imgur.com/Jbow6.png The text is HTML formatted, ...

HTML5 video function is only supported in Internet Explorer, while other browsers display a black screen instead

My task involves creating an html5 application that can be accessed across all major browsers, including Chrome, Firefox, IE9, Safari, and Opera. One of the requirements is for the application to support video playback. I am utilizing the video tag and hav ...

Adjusting the length of the To, CC, and BCC text fields in web design

I'm developing a webpage that will collect email addresses for user notifications. I want to ensure the length limits of the 'to,' 'cc,' and 'bcc' fields. According to RFC 2821/3696, an email address can be up to 256 cha ...

Creating two separate divs that can scroll independently while also limiting each other's scroll depth can be achieved by utilizing

I am attempting to replicate the unique scrolling feature seen on this particular page. Essentially, there are two columns above the fold that can be scrolled independently, but I want their scroll depths to be linked. When a certain depth is reached whil ...

I'm facing an issue with grid-template-area not working properly, even though I've ensured that

My div elements are not aligning with the grid template areas specified in the CSS. When inspecting in Firefox, it shows as "zero one two three four", "five six ... etc." The classes mentioned apply to divs within the container div with a class of "spaces ...

Mastering various techniques for creating styles with makeStyles in React JS Material-UI

As a newcomer to React JS and Material UI, I am experimenting with creating various styles of buttons. Each button should have a unique appearance based on attributes like name= submit, ok, cancel, confirm, alert. App.JS import CssButton from './con ...

Is there a way to transform time into a percentage with the help of the moment

I am looking to convert a specific time range into a percentage, but I'm unsure if moment.js is capable of handling this task. For example: let start = 08:00:00 // until let end = 09:00:00 In theory, this equates to 100%, however, my frontend data ...

Mesh object circling in the opposite direction of the displayed image

Working on replicating a Flash website using Three.JS and facing difficulty in achieving desired functionality. The goal is to create button images that orbit around the center of the screen, stop when hovered over by the mouse, and open a different locat ...