Take a look at this JSFiddle demo
An issue arises when sliding the element as it requires an overflow:hidden
, which also hides the triangle.
To resolve this, you should slide .drop-menu ul
instead of .drop-menu
. You can achieve this easily with:
$('.drop-menu-button').click(function() {
$('.drop-menu').toggleClass('visible');
$('.drop-menu ul').slideToggle();
});
Then use the following selector:
.drop-menu.visible::before
The problem now is that during the upward slide, the triangle disappears initially.
To address this, modify your code to:
$('.drop-menu-button').click(function() {
if($('.drop-menu').hasClass('visible')){
$('.drop-menu ul').slideUp('',function(){
$('.drop-menu').removeClass('visible');
});
}else{
$('.drop-menu').addClass('visible');
$('.drop-menu ul').slideDown();
}
});
Update:
Another solution is to utilize:
$('.drop-menu-button').click(function() {
$('.drop-menu').addClass('visible');
$('.drop-menu ul').slideToggle('',function(){
if(!$(this).is(':visible')){
$('.drop-menu').removeClass('visible');
}
});
});
For a working example, visit: http://jsfiddle.net/SZWmd/31/