мой личный фаворит, попытался gcc 4.6.3 и 4.9.2:
#define STR_(tokens) # tokens
#define ARRAY_SIZE(array) \
({ \
_Static_assert \
( \
! __builtin_types_compatible_p(typeof(array), typeof(& array[0])), \
"ARRAY_SIZE: " STR_(array) " [expanded from: " # array "] is not an array" \
); \
sizeof(array) / sizeof((array)[0]); \
})
/*
* example
*/
#define not_an_array ((char const *) "not an array")
int main () {
return ARRAY_SIZE(not_an_array);
}
компилятор печатает
x.c:16:12: error: static assertion failed: "ARRAY_SIZE: ((char const *) \"not an array\") [expanded from: not_an_array] is not an array"
Вы можете использовать setTimeout()
следующим образом
При первом нажатии кнопки включается класс сразу, при повторном нажатии кнопки через три секунды. Вы можете проверить класс, используя hasClass()
$(".sm-menu").click(function(menu){
if(!$('.menu_ul').hasClass('menu_ul-off')){
$('.menu_ul').addClass('menu_ul-off');
}else{
setTimeout(function(){
$('.menu_ul').removeClass('menu_ul-off');
}, 3000);
}
});
.menu_ul{
display : none;
}
.menu_ul-off{
display : block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="sm-menu">Menu Click<div>
<div class="menu_ul">Menu UL<div>
ИЛИ [1120 ] вы можете использовать delay()
и .queue()
, если хотите добавить класс, а затем удалить класс через 3 секунды на одним щелчком мыши
$(".sm-menu").click(function(menu){
$('.menu_ul').addClass("menu_ul-off").delay(3000).queue(function(next){
$(this).removeClass("menu_ul-off");
next();
});
});
[ 114] <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="sm-menu">Menu Click<div>
<div class="menu_ul">Menu UL<div>