0

jQuery code:

$(window).load(function(){
    $("#slider").flexslider({
        animation: "slide",
        controlNav: false,
        directionNav: false,
        init: function (slider) {
            // lazy load
            $("img.lazy").slice(0,1).each(function () {
                alert('init running');
                var src = $(this).attr("data-src");
                $(this).attr("src", src).removeAttr("data-src").removeClass("lazy");
            });
        },
        before: function (slider) {
            // lazy load
            $("img.lazy").slice(0,2).each(function () {
                alert('before running');
                var src = $(this).attr("data-src");
                $(this).attr("src", src).removeAttr("data-src").removeClass("lazy");
            });
        },
        animationLoop: false,
        slideshow: false,
        sync: "#carousel",
    })
})

JSFIDDLE URL:

https://jsfiddle.net/6z5L31tg/

init function is not working. even it not alerting me. can you please explain to me why it not working? and How can I resolve this issue? I am weak in English. please apologize me if I made any Grammatical or Spelling mistakes.

Shah Rushabh
  • 147
  • 4
  • 16

1 Answers1

1

You are using the .load() event, which was replaced by the same named ajax method in jQuery 3.0.

From the upgrade guide:

The event .load() method conflicted with the ajax .load() method. The .error() method could not be used with window.onerror because of the way the DOM method is defined. If you need to attach events by these names, use the .on() method, e.g. change $("img").load(fn) to $(img).on("load", fn).

I would also advise you to load the slider when the DOM is ready. I updated your fiddle: https://jsfiddle.net/6z5L31tg/2/

secelite
  • 1,353
  • 1
  • 11
  • 19
  • 1
    Correct, now correct way is `$(window).on('load', ...)`. More information to thore ready handlers: http://stackoverflow.com/questions/38585373/why-is-my-load-event-function-not-beeing-executed-after-switching-to-jquery-3 – eisbehr Nov 14 '16 at 12:17