If I run the function below before defining it, I will get this error...
Uncaught ReferenceError: openModal is not defined
run then define
$(document).ready( function() {
delay(openModal, 2000);
delay = function (f, t) {
setTimeout(function() {
f();
}, t);
};
openModal = function () {
$('#modal-box').css( {
left: $(window).width() / 2 - $('#modal-box').width() / 2,
top: $(window).height() / 2 - $('#modal-box').height() / 2
} );
$('#modal-box').show();
$('#modal-mask').show();
};
});
Now if I define the function first and then call it it works...I have a background in PHP so I am used to being able to access functions globally, am I doing something wrong or do all functions have to be defined before they can be used?
$(document).ready( function() {
delay = function (f, t) {
setTimeout(function() {
f();
}, t);
};
openModal = function () {
$('#modal-box').css( {
left: $(window).width() / 2 - $('#modal-box').width() / 2,
top: $(window).height() / 2 - $('#modal-box').height() / 2
} );
$('#modal-box').show();
$('#modal-mask').show();
};
delay(openModal, 2000);
} );