Sometimes my event listeners work and the elements trigger the events, other times they do not. I believe it is due to a delay. However chrome states the page is fully loaded by the time. I'm clicking on elements. It is a matter of seconds, not milliseconds.
require(['jquery'],function($){
$(window).load(function() {
// Added event listeners here.
});
});
Has anyone else encountered this?
-
try adding timeout - stackoverflow.com/questions/8252638/…Reena Parekh– Reena Parekh2016年07月21日 09:43:04 +00:00Commented Jul 21, 2016 at 9:43
1 Answer 1
I faced the same problem. The solution worked for me after adding the js in function and calling that function.
function test() {
require(['jquery'], function ($) {
$(window).load(function () {
// Added event listeners here.
});
});
}
For example if you are using the Carousel. I created the delay of one second then I don't face this issue.
function slider() {
require(['jquery', 'jquery/ui'], function ($) {
$(document).ready(function () {
$("#banner_slider").owlCarousel({
navigation: false,
slideSpeed: 300,
paginationSpeed: 400,
singleItem: true,
pagination: true,
rewindSpeed: 500
});
window.clearTimeout();
});
});
}
setTimeout(slider, 1000);