JQuery: automatically start freeze

I have a mouseout mouseout mouseout setting as follows for a list item:

$("#main-nav li a").hover(function() {
                $el = $(this);
                leftPos = $el.position().left;
                newWidth = $el.parent().width();
                $magicNav.stop().animate({
                    left: leftPos,
                    width: newWidth
                });
            }, function() {
                t1 = $(".current-menu-item a").position().left;
                t2 = $(".current-menu-item a").parent().width();
                $magicNav.stop().animate({
                    left: t1,
                    width: t2
                });    
            });

And I want to automatically launch guidance on ".current-menu-item a" as soon as someone enters the site or the page loads.

I am currently using $(".current-menu-item a").trigger('hover');and it is not working.

reference

+5
source share
4 answers

use this

$(document).ready(function(){
    $(".current-menu-item a").mouseover();
});

or

$(window).load(function(){
    $(".current-menu-item a").mouseover();
});
+8
source
$(".current-menu-item a").trigger('mouseenter');

Guidance is not a real event (it is a contrived jQuery consisting of mouseenterand mouseleave). In any case, this is a two-stage process, so it does not logically start.

+2
source

you need to use mouseover to not freeze like that

$(".current-menu-item a").trigger('mouseover');

0
source
$('selector').trigger('eventName');
0
source

All Articles