简体   繁体   中英

jquery in ajax.load loader showing every “mouseover”

i hope subject is clear, i try to explain better my problem.

I have a menu and i'd like to load submenu just on mouseover on parent li of menu. It works, but every time i go on parent, i see loader. I'd like that loader to be visible just on first mouseover. You can see it here: http://v2.profumee.com

Thanks in advance.

This is the code:

function pageLoad() {

            var SessionLingua = '<%= Session("Lingua") %>';

            $(".LinkPadreBoxMenu").mouseover(function (event) {
                    event.preventDefault(); //preventing button's default behavior
                    var IDCategoriaGenitore = $(this).next("#LblIDCategoria").html();

                    $('.A_' + IDCategoriaGenitore).show();

                    $(".SottoCategorieAjax_" + IDCategoriaGenitore).load('/' + SessionLingua + '/ajax_categorie.aspx', { 'IDCategoriaGenitore': IDCategoriaGenitore }, function () {
                        $('.A_' + IDCategoriaGenitore).hide();
                    });
                    event.stopPropagation();
                });

        }

Use localStorage to store some value on ajax call. Now next time when you hover, check whether you have localstorage value. By this, you can condition you loading image.

function pageLoad() {

            var SessionLingua = '<%= Session("Lingua") %>';
            var vars = {};

            $(".LinkPadreBoxMenu").mouseover(function (event) {
                    event.preventDefault(); //preventing button's default behavior
                    var IDCategoriaGenitore = $(this).next("#LblIDCategoria").html();


                    if (vars['Menu' + IDCategoriaGenitore] != true){
                        $('.A_' + IDCategoriaGenitore).show();

                        $(".SottoCategorieAjax_" + IDCategoriaGenitore).load('/' + SessionLingua + '/ajax_categorie.aspx', { 'IDCategoriaGenitore': IDCategoriaGenitore }, function () {
                            $('.A_' + IDCategoriaGenitore).hide();
                            vars['Menu' + IDCategoriaGenitore] = true;
                        });
                        event.stopPropagation();
                    }
                });

        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM