I'm attempting to achieve a particular effect onclick
. I've created an angled or razor-blade style div
using a parent div-element
, and a pseudo-element :after
(see snippet below). What I'm trying to make happen is when the user clicks on the parent element, the skew property I have set up, shifts to a different skewed angle.
My problem is what regardless of whether I call the parent or the pseudo, onclick
I cannot get the animation to work. Can anyone point me in the right direction?
$(document).ready(function() {
$('.slantedDiv').click(function() {
$('.slantedDiv .slantedDiv:after').toggleClass('active');
});
});
* {
padding: 0;
margin: 0;
}
.slantedDiv {
position: relative;
width: 100%;
height: 300px;
background-color: yellow;
}
.slantedDiv:after {
position: absolute;
width: 100%;
height: 100%;
content: '';
background: inherit;
top: 0;
right: 0;
bottom: 0;
left: 0;
transform-origin: top left;
transform: skewY(10deg);
transition: all .3s ease-in-out;
}
.active {
transform-origin: top right;
transform: skewY(-10deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="slantedDiv"></div>