Bonjour,

J'ai un problème sur ce script avec la propriété onScroll le déboguer me dit qu'elle n'est pas définie (sous wordpress) alors que sur une page html, cela fonctionne bien.
Je vous remercie de votre aide.

Code pour Wordpress avec l'erreur "Uncaught ReferenceError: onScroll is not defined":

Code :

(function($){
    $(document).ready(function () {
        $(document).on("scroll", onScroll);
        $('a[href^="#"]').on('click', function (e) {
            e.preventDefault();
            $(document).off("scroll");

            $('a').each(function () {
                $(this).removeClass('link-active');
            })
            $(this).addClass('link-active');

            var target = this.hash,
            menu = target;
            $target = $(target);
            $('html, body').stop().animate({
                'scrollTop': $target.offset().top+2
            }, 500, 'swing', function () {
                window.location.hash = target;
                $(document).on("scroll", onScroll);
            });
        });
    });
})(jQuery);

Code sur ma page html qui fonctionne bien:
Code :

$(document).ready(function () {
            $(document).on("scroll", onScroll);

    $('a[href^="#"]').on('click', function (e) {
        e.preventDefault();
        $(document).off("scroll");

        $('a').each(function () {
            $(this).removeClass('link-active');
        })
        $(this).addClass('link-active');

        var target = this.hash,
        menu = target;
        $target = $(target);
        $('html, body').stop().animate({
            'scrollTop': $target.offset().top+2
        }, 500, 'swing', function () {
            window.location.hash = target;
            $(document).on("scroll", onScroll);
        });
    });
});

        function onScroll(event){
            var scrollPos = $(document).scrollTop();
            $('#top-menu a').each(function () {
                var currLink = $(this);
                var refElement = $(currLink.attr("href"));
                if (refElement.position().top <= scrollPos && refElement.position().top + refElement.height() > scrollPos) {
                    $('#top-menu li a').removeClass("link-active");
                    currLink.addClass("link-active");
                }
                else{
                    currLink.removeClass("link-active");
                }
            });
        }

Aucune réponse