I have next code structure:
global.js and *.js for each page. Lets take for example global.js and main_menu.js.
I have some elements, that have class ripple_effect, when elements with this class get clicked, the animation begins that runs 650ms, so in order to let users see the animation i try to make a small delay in code ( i know this is not good, but still ).
in global.js i have next code:
var delayForRipple = 300;
function Execute(func) {
setTimeout(func(), delayForRipple);
}
in main_menu.js i have next code:
$(this).on('click', ".menu_button", function (e) {
href = $(this).attr('id');
Execute(function () {
window.location.href = href;
});
});
But this code executes immediately. How can i fix it?
Here is a fiddle for fast reproduction:
var delayForRipple = 300;
$(".wrapper").on('click', "#clickMe", function (e) {
Execute(function () {
alert("TEST");
});
});
function Execute(func) {
setTimeout(func(), delayForRipple);
}
.test_element {
height:100px;
width:100px;
background-color:red;
}
<div class="wrapper">
<div id="clickMe" class="test_element"></div>
</div>
setTimeoutexpects a function reference (or a string), but you're callingfunc(), which doesn't return a reference, it just redirects ...