Ways to Randomly Flip Divs

I have developed an application where all divs flip vertically on hover. I am looking for a way to make the flipping random without requiring a hover. Any ideas on how to achieve this?

.vertical.flip-container {
  position: relative;
  float: left;
  margin-left: 50px;
}

.vertical .back {
  transform: rotateX(180deg);
}

.vertical.flip-container .flipper {
  transform-origin: 100% 50px;
}

.vertical.flip-container:hover .flipper {
  transform: rotateX(-180deg);
}

.flip-container {
  perspective: 1000;
}


/* flip the pane when hovered */

.flip-container:hover .flipper,
.flip-container.hover .flipper {
  transform: rotateY(180deg);
}

.flip-container,
.front,
.back {
  width: 100px;
  height: 100px;
}

.flipper {
  transition: 0.6s;
  transform-style: preserve-3d;
  position: relative;
}

.front,
.back {
  backface-visibility: hidden;
  position: absolute;
  top: 0;
  left: 0;
}
<div class="flip-container vertical" ontouchstart="this.classList.toggle('hover');">
  <div class="flipper">
    <div class="front" style="background: red">
      John
    </div>
    <div class="back" style="background:green">
      Doe
    </div>
  </div>
</div>

<div class="flip-container vertical" ontouchstart="this.classList.toggle('hover');">
  <div class="flipper">
    <div class="front" style="background: red">
      Jane
    </div>
    <div class="back" style="background:green">
      Smith
    </div>
  </div>
</div>


<div class="flip-container vertical" ontouchstart="this.classList.toggle('hover');">
  <div class="flipper">
    <div class="front" style="background: red">
      Bob
    </div>
    <div class="back" style="background:green">
      Johnson
    </div>
  </div>
</div>

If you have any suggestions, please feel free to share them. Thank you.

Answer №1

I revamped the markup and CSS for a more sleek appearance with added depth. Utilize the setInterval method to smoothly transition on hover:

http://jsfiddle.net/7x75466y/5/

var $flippers = $(".flip-container"),
    qtFlippers = $flippers.length;

setInterval(function () {
    $flippers.eq(Math.floor(Math.random()*qtFlippers)).toggleClass('hover');
}, 1000);

Answer №2

Check out this JSfiddle where a random tile is selected and an action is applied to it every second using setTimeout. Feel free to customize the action on the tile. This script utilizes jQuery.

http://jsfiddle.net/3mb1uqox/4/

var elements = $(".tile-element")
setInterval(function() {
    var chosenElement = elements.eq(Math.floor(Math.random() * elements.size()))
    chosenElement.animate({ opacity: 0.5 }) //CUSTOMIZE ACTION HERE
}, 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

What varieties of ajax styles are there?

Although I am still relatively new to utilizing ajax, I have found a lot of success in my endeavors so far. The majority of my ajax calls tend to follow this format: function saveQueryProf(){ var currentDate = new Date(); var date=currentDate. ...

Guide to using AES-256-CBC encryption in Node.js and decrypting with OpenSSL on a Linux system

Question: Hello there, I am currently facing an issue with decrypting my encoded base64 using a specific command. Here is the command that I am trying to use: echo "base64key" | (openssl enc -AES-256-cbc -d -a -pass "pass:test" -pbkdf2 ...

OpenLayers 4 - adjusting the view to the boundaries of chosen features

Hey everyone, I ran into an issue yesterday with zooming to selected features and I'm hoping someone can point me in the right direction. Here's the situation... I'm working on implementing an autocomplete/search bar using the Materialize M ...

The JSON response is not being returned by the static React App hosted on Microsoft

Seeking assistance from anyone who may have faced and resolved a similar issue. Our React application is deployed on Azure Static Web App and operates smoothly, but we are stuck on configuring it to return JSON instead of HTML in its responses. Within our ...

Guide on changing the background image of an active thumbnail in an autosliding carousel

My query consists of three parts. Any assistance in solving this JS problem would be highly appreciated as I am learning and understanding JS through trial and error. I have designed a visually appealing travel landing page, , featuring a thumbnail carous ...

Limiting Selection of Specific Days in jQuery Date Picker

I am currently working on a project that involves two date pickers. The first one is for the Start Date and the second one is for the End date. My goal is to disable days in the "End date" date picker which are before the selected date in the Start date. ...

A step-by-step guide on setting up flow types for @material-ui/core version 4

Is there a way to install flow types for material-ui/core version 4.x.x? It seems like the last update was for version 1.x.x here. The documentation on this topic is quite limited here. I'm unsure if there is still support for this, especially since t ...

Resolve the issue of autofill data overlapping with field labels

My form incorporates the Canada Post AddressComplete tool, which functions similarly to Google Maps Autocomplete. As you type your address, suggestions appear in a drop-down menu. However, after selecting an address, the text in the Postal Code and City f ...

Mastering the art of chaining promises in Mongoose

I need help figuring out how to properly chain promises for a "find or create" functionality using mongodb/mongoose. So far, I've attempted the following: userSchema.statics.findByFacebookIdOrCreate = function(facebookId, name, email) { var self = ...

Creating a dynamic image viewing experience similar to Facebook's image viewer using jQuery

Here are two div tags that show the previous and next images from the large image collection: <div class="alignleft"><a href="1005.php"><img width="50" height="50" src="thumb-98.jpg" class="previous"></a></div> <div class ...

Connecting an HTML button to a Python script

I'm struggling to connect my HTML form with a Python script in order to send an email to the recipient. Despite researching various websites, I can't seem to successfully send the message that I've inputted into the text box. Here's my ...

JavaScript function unable to access static file for image

I need assistance with dynamically displaying an image (a checkmark or "X") based on a variable. When I insert the image using a script directly in the HTML file, it functions correctly. However, when attempting to set the image from within the createEasyD ...

Using JavaScript to Access PHP Files

Would like to understand the process of calling a php file (test.php) from either "x:" or "y:" in the code below. var example1 = { x: ['giraffes', 'orangutans', 'monkeys'], y: [20, 14, 23], name: 'Most read', ...

Retrieve the value of the option that has been selected

I've been searching tirelessly, but I just can't seem to find the answer online or figure out the correct code on my own. Although I did manage to make it work with jQuery, I need to switch over to using YUI 2.7. So, what exactly am I trying to ...

Utilizing the .fadeToggle() function to create a fading effect for text, which fades in and out

I am on the verge of achieving my goal, but I could use a little more assistance with this. $('.change').hover(function() { $(this).fadeToggle('slow', 'linear', function() { $(this).text('wanna be CodeNinja' ...

Exploring the outer scope within JavaScript

Currently, I am working on a JavaScript code snippet where I am attempting to set the 'obj' variable from the success and error callbacks. However, it seems like the scope of the 'toLinkInfo' function is not encompassing these callbacks ...

Load content within the DIV container

I need help finding code that can use JQuery to load a page into a DIV element. Essentially, I want to load displaycatch.php into a specific DIV <div id="results">Content for id "results" Goes Here</div> Furthermore, I would like to add a ...

Having trouble loading mtl file in Three.js with map_ks and bump instructions?

I am currently working with an MTL file that contains the following specifications: newmtl blinn_backSG illum 4 Kd 0.17 0.15 0.28 Ka 0.00 0.00 0.00 Tf 1.00 1.00 1.00 bump -s 0.1 0.1 canvas_specular.tif -bm 0.025 Ni 1.00 Ks 0.00 0.00 0.00 map_Ks -s 0.1 0.1 ...

What are effective strategies to stop the generic * { … } style from overriding its parent tag?

How can I prevent my general * { ... } style from overriding the parent tag? In the given scenario, I want the text "sssssssss" to have the style text-huge. .text-huge { font-size: 28px !important; color: green !important; } * { font-size: 12px; ...

Getting around CloudFlare's 100-second time-out restriction

Seeking a solution to AJAX-enable my reports and circumvent the 100-second time-out constraint enforced by CloudFlare for requests passing through its platform. For more information, visit Is it possible to increase CloudFlare time-out? The implementatio ...