I have a basic page where you can click on several button to show a popup. In this popup you have different button that onClick event make a div slideUp and show some newContent.
My problem comes from the fact that when you click on the different buttons a class is removed from a and added to the current one. But since remove this class and putting it back is a fast operation my css transition property doesn't have time to notice the modification (i guess) and therefore doesn't play the animation.
My idea to solve this was to put a sleep function be after removing the class so css has time to take effect and then putting it back on another div. BUT it doesn't always work, it gets triggered inconsistantly.
I can't provide any fiddlelink or use SO's snippet thing. I don't have full access to the internet only few website are avialable to me like SO or Microsoft MSDN.
Here's is my html:
<html>
<body>
<div>
<input type="button" style='width : 100px; height: 100px; padding-left: 30px;' value="B2" onclick="removeAll();document.getElementById('customFilterRSp2').style.display='block';"/>
</div>
<div id="customFilterRSp2" class="filterRSp" >
<div class="wraper">
<div >
<input type="button" value="Opt1" style = "float: left" onclick="SlideUp(this.parentNode.parentNode,2);"/>
<input type="button" value="Opt2" style = "float: left" onclick="SlideUp(this.parentNode.parentNode,3);"/>
<input type="button" value="close" style = "float: right" onclick="closeSlide(this.parentNode);"/>
</div>
</div>
<div id="subCustomFilter3" class="subfilterRSp">
<div >
<input type="button" value="SOUS OPT 2" style = "float: left" onclick="SlideUp(this.parentNode.parentNode,3);"/>
<input type="button" value="close" style = "float: right" onclick="closeSlide(this);"/>
</div>
</div>
<div id="subCustomFilter2" class="subfilterRSp">
<div >
<input type="button" value="SOUS OPT 1" style = "float: left" onclick="SlideUp(this.parentNode.parentNode,2);"/>
<input type="button" value="close" style = "float: right" onclick="closeSlide(this);"/>
</div>
</div>
</div>
</body>
<html>
CSS:
<style>
.wraper{
height: 100%
}
.subfilterRSp{
display : none;
position : relative;
margin-left: -20px;
left : 0;
width : 100%;
height : 470px;
padding : 20px;
box-shadow : 0 0 10px 0px rgba(50,50,50,0.3);
background-color : white;
z-index: 1000;
overflow: auto;
}
.filterRSp{
display : none;
position : relative;
left : 10%;
width : 80%;
height : 400px;
padding : 20px;
box-shadow : 0 0 10px 0px rgba(50,50,50,0.3);
background-color : white;
z-index: 1001;
overflow: hidden;
}
.slideUp{
height: 30px;
overflow: hidden;
border-radius: 4px 4px 0 0;
-webkit-transition: height 0.2s;
-moz-transition: height 0.2s;
-ms-transition: height 0.2s;
-o-transition: height 0.2s;
transition: height 0.2s;
z-index : 1100
}
And the faulty javascript:
<script>
function closeSlide(el){
el.parentNode.parentNode.style.display = "none";
}
function SlideUp(el, n){
els = document.querySelectorAll('.slideUp');
for (var i = 0; i < els.length; i++) {
els[i].classList.remove('slideUp');
}
els = document.querySelectorAll('.currentSlideUp');
for (var i = 0; i < els.length; i++) {
els[i].classList.remove('currentSlideUp');
els[i].style.display = "none";
}
setTimeout(function(){
el.className += " slideUp";
var curEl = document.getElementById('subCustomFilter'+n);
curEl.className += " currentSlideUp";
curEl.style.display = "block";
}, 10);
}
function removeAll(){
var els = document.querySelectorAll('.subfilterRSp');
for (var i = 0; i < els.length; i++) {
els[i].style.display = 'none';
}
els = document.querySelectorAll('.slideUp');
for (var i = 0; i < els.length; i++) {
els[i].classList.remove('slideUp');
}
els = document.querySelectorAll('.filterRSp');
for (var i = 0; i < els.length; i++) {
els[i].style.display = 'none';
}
}
To see the problem click between Opt1 and Opt2 it will make divs slideUp and sometimes it will just switch to another div without the animation.