-2

For the following HTML:

<li id="li1">
    <div id="card-container">
        <div id="card">
            <div class="front">
            <img id="track_image" src="image.jpg" />
        </div>
        <div class="back">
            <div id="controls">
                <audio controls></audio>
            </div>
        </div>  
    </div>
</li>

I have the following CSS, which will flip it on hover.

#card-container:hover .back {   
    -webkit-transform: rotateX(0deg);
}

#card-container:hover .front {      
    -webkit-transform: rotateX(-180deg);
}

But I want to change it so the flip instead happens on a click, I've attached a click listener and am trying this code below but it doesn't do anything

function click(evt, listElementId) {
       var listElement = document.getElementById(listElementId);
       var front = listElement.getElementsByClassName("front")[0];
       front.style.webkitTransition = "rotateX(-180deg)";
       var back = listElement.getElementsByClassName("back")[0];
       back.style.webkitTransition = "rotateX(0deg)"

What should the JavaScript be to achieve the same as the CSS is doing?

2 Answers 2

2

You have confused transitions and transformations. According to this answer, you should use

front.style.webkitTransform = "rotateX(-180deg)";
Sign up to request clarification or add additional context in comments.

Comments

0

Use a class:

#card-container.flipped .back {   
    -webkit-transform: rotateX(0deg);
}

#card-container.flipped .front {      
    -webkit-transform: rotateX(-180deg);
}
function click(evt, listElementId) {
    document.getElementById(listElementId).classList.add('flipped');
}

3 Comments

Still nothing happens when I try that.
@minitech: You might use .toggle() :-)
@Aminoacids: How did you attach the listener? Show us the code. Also, does you UA support classList?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.