Preventing the flipping effect with jquery flippy

Hey there! I've been using a cool flippy jquery plugin that I found on this website. It's working great, but I have run into an issue. When the element flips, I want to include a button on the flip side that takes the user to a different page.

The problem is that if any div inside the flipped element is clicked, it triggers the flipping animation again.

I'm looking for a solution to prevent the flip from happening when a div within the flipped element is clicked.

Check out my code here: http://jsfiddle.net/hw7rP/2/

<div class="left bigbox sponsor">
    <div class="sponsorFlip">
        the front
    </div>

    <div class="sponsorData">
        <div class="ifIgetClickedDontFlip">click me</div>
    </div>
</div>

JavaScript:

$('.sponsorFlip').bind("click",function(){
    var elem = $(this);
    
    if(elem.data('flipped'))
    {
        elem.revertFlip();
        elem.data('flipped',false)
    }
    else
    { 
        elem.flip({
            direction:'lr',
            speed: 350,
            color: '#000',
            onBefore: function(){
                elem.html(elem.siblings('.sponsorData').html());
            },
            onEnd: function(){
                //ajax requests every second
            }
        });
        
        elem.data('flipped',true);
    }
});

Can anyone provide some assistance with this? Thank you!

Answer №1

If you decide to redirect to a different page after flipping, simply click on the page or button again to make it happen.

$('.sponsorFlip').bind("click",function(){
    // $(this) point to the clicked .sponsorFlip element (caching it in elem for speed):
    var elem = $(this);
    // data('flipped') is a flag we set when we flip the element:
    if(elem.data('flipped'))
    {
      // If the element has already been flipped

      // Your code to redirect it to another page goes here.

     }else{ // Using the flip method defined by the plugin:
           elem.flip({
           direction:'lr',
           speed: 350,
           color: '#000',
           onBefore: function(){
            // Insert the contents of the .sponsorData div (hidden
            // from view with display:none) into the clicked
            // .sponsorFlip div before the flipping animation starts:

                       elem.html(elem.siblings('.sponsorData').html());
                      },
              onEnd: function(){
            //iniatiate ajax requests every second
                     }
           });
        // Setting the flag:
        elem.data('flipped',true);
     }
});

Within if(elem.data(flipped)), insert the code to redirect to the desired page.

Answer №2

To ensure that the element clicked or any of its parent elements do not have the class .doNotFlipMe, and if they do, prevent flipping. Simple!

HTML:

<div class="left bigbox sponsor">
    <div class="sponsorFlip">the front</div>
    <div class="sponsorData">
        <div>Some other content here
            <div class='doNotFlipMe'><a href="www.somesite.com">click me</a>
            </div>
        </div>
    </div>
</div>

Javascript:

$('.sponsorFlip').bind("click", function (e) {
        var elem = $(this);
        if (elem.data('flipped')) {
            targetEl = $(e.target);
            if (targetEl.hasClass('doNotFlipMe') || targetEl.parents('.doNotFlipMe').length) {
                // Do nothing
            } else {
                elem.revertFlip();
                elem.data('flipped', false);
            }
        }

Demo: http://jsfiddle.net/robschmuecker/5EnfW/

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 is the best way to retrieve the page slug within the layout file in Next.js, specifically when using the app folder structure?

In my latest project, I have implemented a nested layout using the new app folder. Within this layout, I have included a header that appears across all pages in the path www.mysite.com/some-slug. One issue I am facing is with the signup button located in t ...

Exploring the various possibilities of establishing multiple types of many-to-many relationships between two tables using Sequelize technology

Working with Sequelize in Node, I am dealing with Users and items. A user can interact with an item in various ways, such as voting or commending, which are distinct actions in this scenario. Initially, I considered having two separate many-to-many relati ...

Maximizing the power of datatables with ajax integration

Exploring pagination with AJAX on datatables.net is something I want to try. I have two input fields where users can enter start and end dates, followed by the table structure below: <table class="table table-hover" id="example"> < ...

What could be causing the failure of isElementPresent function?

Here is a simple code snippet that waits for a dropdown list to be displayed on the page: var By = this.webdriver.By; var driver = this.driver; var bySelector = By.xpath('//*[@id="searchForm"]//*[@class="autocomplete-suggestions autocomplete-suggesti ...

Struggling to make the ajax callback function functional?

I'm working on a JavaScript function to save data and once successful, I want to hide the form and display a success message. Here's what I have so far: $.ajax({ type: "POST", url: "<?php echo dirname(WP_PLUGIN_URL.'/&apo ...

Angular.js hierarchical model issue: grandchildren functionality not functioning as expected

Currently, I am delving into the world of Angular and exploring its functionalities. My main goal is to construct a hierarchical data structure that can be easily manipulated using a hierarchical view: Root: - addChild - child 1: { remove, addChild, c ...

Tips for anchoring an element when scrolling reaches its highest point

Is there a way to keep a div element fixed in its original place when scrolling through it, so that it locks into position once we reach a certain point? I've tried using CSS position:fixed; without success. I have noticed this technique on many webs ...

Attempting to dynamically fill a dropdown menu based on the values chosen in the two previous selections

Could you please assist in identifying the issue with the code below? I am attempting to populate a select option based on the selections from two previous select options. For instance, after selecting option 1 and then option 2, the third option should be ...

Can you guide me on creating a post and get request using ReactJS, Axios, and Mailchimp?

I am brand new to ReactJS and I am currently working on developing an app that requires integration with Mailchimp to allow users to subscribe to a newsletter. I am looking for assistance on making a request using axios. Where should I input my API key? ...

The Google font feature is causing an issue where text cannot be selected when trying to print a

I am in the process of creating a Vue application to generate my CV in PDF format. I have incorporated the Google font Montserrat into the project, but when I attempt to print the page to file (CTRL + P in Firefox), the text appears as if it were an image ...

Browse through different states by clicking on the <a> </a> tag

Is there a way to switch between states defined by $stateProvider when clicking on the <a> </a> tag? Below are the states I have set up: $stateProvider //region page States .state('page1', { url: "/pg1", ...

Challenges faced when subscribing to global events in JavaScript

I have some questions about the JavaScript code snippet below: What does .events.slice(-1)[0][0] signify? Similarly, could you explain the purpose of nodes_params += "&ns=" + GLOBAL_EVENT + "," + start_from + ",-,-";? Could you elaborate on what is m ...

The webpage containing the authRequired meta briefly flashes on the screen, even if there are no active login sessions on Firebase

As a beginner in Vue and web development, I have been enjoying my journey so far but now I find myself stuck. Currently, I am working on creating an admin dashboard with Firebase authentication. Everything seems to be functioning as expected, except for on ...

The images in Bootstrap 5 are displayed individually on separate lines, even though they could easily be accommodated within a

I'm facing an issue with displaying several 50x50 images in a row of 6 columns on my website. Despite the simple code setup, each image appears on its own row, creating the illusion of stacked images rather than a single row. This is the code structu ...

Using Threejs JSONLoader and OOP to easily add models to a scene post-loading

I am working on incorporating the THREE JSONLoader into a "Scenemanager" Object that manages the addition and removal of objects and models. My main goal is to deepen my understanding of OOP, JS, and Threejs. Within App3D (which oversees the scene), I cal ...

Ways to break apart a string of text without a regular pattern

Here is the data I am working with: Huawei Y7P Art-L28 (4/64gb) (AAAAAAAAAAAAAA) EXP:02/19/2020 Huawei Y9 prime 2019 (BBBBBBBBBBBBBBB) EXP:07/17/2019 Oppo A31 4gb/128gb (CCCCCCCCCCCCCCC) Vivo Y15 5000mah 4GB/64GB (1901) (DDDDDDDDDDDDDDD) EXP:06/14/2019 I ...

Setting up GameClosure on a Windows machine

Is it possible to install GameClosure on Windows? The installation guide mentions that only OSX is officially supported, but there have been reports of success running it on Linux and Windows. However, the process for doing this is not well-documented. A ...

Ensure that the images in the final row of the flexbox gallery are consistent in size with the rest

I'm working on creating a CSS flex image gallery that adjusts the width of the images based on the container size: HTML: <div class="grid-container"> <div class="grid-item"> <img src="small-thumb-dpi.jpg" /> < ...

What could be causing Jest to prevent me from using the node testing environment, especially when they have made changes to it?

I am currently working on testing a React component within Next.js using Jest. Jest made an official announcement regarding the change of default test environment to Node: Due to this update, the default test environment has been switched from "jsd ...

Progress bar for AJAX file loading for Flash player

Looking to create a progress bar using AJAX for a flash file. Check out this demo here: I tried to analyze their page, but the JavaScript is encrypted and I'm not very skilled in JS. Any suggestions? Thank you! ...