jQuery:自动触发悬停 [英] jQuery: Automatically trigger hover

查看:89
本文介绍了jQuery:自动触发悬停的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $(#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
});
});

我想尽快在'.current-menu-item a'上自动触发悬停有人进入网站或加载页面。



目前,我使用 $(。current-menu-item a)。触发器('hover'); 并且不起作用。



帮助?

解决方案

使用这个

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

  $(window).load(function(){
$(。current-menu-item a)。mouseover();
});


I have a hover mousein mouseout setup 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 trigger a hover on '.current-menu-item a' as soon as someone enters the website or the page is loaded.

At the moment, i use $(".current-menu-item a").trigger('hover'); and it doesn't work.

Help?

解决方案

use this

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

or

$(window).load(function(){
    $(".current-menu-item a").mouseover();
});

这篇关于jQuery:自动触发悬停的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆