I'm having a problem with jQuery animate and CSS selectors.
What I am trying to achieve is when the div (first box, the other two don't work yet) is clicked on (inside the .work-piece div), the height changes to calc(100% + 75px) and the colour also changes. Not just that, but when the user clicks anywhere outside that div, it reverts back to its normal form. I have tried using the :not() selector, but can't get anywhere.
Also, I don't know why, but when I click on the div, it loops six times over.
Any help would be appreciated.
Thanks.
http://codepen.io/DocRow10/pen/pgRXdv
$(document).ready(function() {
$(".work-piece > div").on('mouseover', function() {
$(this).fadeTo("slow", 0.8);
console.log("I dunno...");
});
$(".work-piece > div").on('mouseleave', function() {
$(this).fadeTo("slow", 0);
console.log("I dunno...");
});
// .hover or use on('mouse...)
// $(".work-piece > div").on('click', function() {
// $(this).animate({backgroundColor: "rgb(0, 197, 205)"},"200");
// console.log("I dunno...");
// });
$(":not(.work-piece > div)").on('click', function() {
$(".work-piece > div").animate({
backgroundColor: "rgb(238, 0, 0)",
height: "+=75px"
}, "200");
$(this).fadeTo("slow", 1);
console.log("I dunno... 'cuz");
});
});
.work-row {
margin-left: auto;
margin-right: auto;
width: 80%;
height: 200px;
border-style: solid;
border-width: 2px;
}
.divider-row {
margin-left: auto;
margin-right: auto;
width: 100%;
height: 75px;
}
.work-piece {
height: 100%;
width: 31%;
background-color: black;
display: inline-block;
margin: 0;
vertical-align: top;
}
.work-piece > div {
background-color: rgb(230, 230, 230);
width: 100%;
height: 100%;
opacity: 0;
display: inline-block;
}
h3.project-name {
font-family: insolent;
font-size: 30px;
text-align: center;
position: relative;
top: 37.5%;
color: rgb(105, 105, 105);
margin-top: auto;
}
.divider-column {
margin: 0;
width: 3.5%;
height: 100%x;
display: inline-block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="work-row">
<div class="work-piece">
<div>
<h3 class="project-name">Guess the Shape</h3>
</div>
</div>
<!--
-->
<div class="divider-column"></div>
<!--
-->
<div class="work-piece"></div>
<!--
-->
<div class="divider-column"></div>
<!--
-->
<div class="work-piece"></div>
</div>