jquery setinterval不工作

jquery setinterval不工作,jquery,setinterval,Jquery,Setinterval,我有这个: $("#nav-reflection li").append("<span></span>"); // Animate buttons, move reflection and fade $("#nav-reflection a").hover(function() { $(this).stop().animate({ marginTop: "-10px" }, 200); $(this).p

我有这个:

    $("#nav-reflection li").append("<span></span>");    

    // Animate buttons, move reflection and fade

    $("#nav-reflection a").hover(function() {
        $(this).stop().animate({ marginTop: "-10px" }, 200);
        $(this).parent().find("span").stop().animate({ marginTop: "18px", opacity: 0.25 }, 200);
    },function(){
        $(this).stop().animate({ marginTop: "0px" }, 300);
        $(this).parent().find("span").stop().animate({ marginTop: "1px", opacity: 1 }, 300);
    });

/* =Shadow Nav
-------------------------------------------------------------------------- */

    // Append shadow image to each LI

    $("#nav-shadow li").append('<img class="shadow" src="http://admin.focuswebmedia.com/wp-content/themes/fwm/images/icons-shadow.jpg" width="79" height="19" alt="" />');
    //$("#slider_right").append('<div id="porfolio_contact_text">Our Porfolio&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Contact Us</div>');
    // Animate buttons, shrink and fade shadow

    $("#nav-shadow li").hover(function() {
        var e = this;
        $(e).find("a").stop().animate({ marginTop: "-14px" }, 250, function() {
            $(e).find("a").animate({ marginTop: "-10px" }, 250);
        });
        $(e).find("img.shadow").stop().animate({ width: "80%", height: "20px", marginLeft: "8px", opacity: 0.25 }, 250);
    },function(){
        var e = this;
        $(e).find("a").stop().animate({ marginTop: "4px" }, 250, function() {
            $(e).find("a").animate({ marginTop: "0px" }, 250);
        });
        $(e).find("img.shadow").stop().animate({ width: "100%", height: "27px", marginLeft: "0", opacity: 1 }, 250);
    });
但是什么都没发生。。。
有什么想法吗?

您可以触发悬停事件:

window.setInterval(play_ani, 5000);

function play_ani() {
 $("#nav-reflection a").trigger('mouseover');
}
我认为你的代码没有任何作用,因为你没有触发效果


更新-您必须触发鼠标悬停并使用$not$j-例如fiddle:

您应该触发
mmouseenter
事件

但是,最好将该代码移动到一个单独的函数中,并从两个位置调用它:

function play(elem) {
    elem.stop().animate({ marginTop: "-10px" }, 200);
    elem.parent().find("span").stop().animate({ marginTop: "18px", opacity: 0.25 }, 200);

$("#nav-reflection a").hover(function() {
    play($(this));
}, function(){
    $(this).stop().animate({ marginTop: "0px" }, 300);
    $(this).parent().find("span").stop().animate({ marginTop: "1px", opacity: 1 }, 300);
});

setInterval(function() { play($("#nav-reflection a"); }, 5000);

错<代码>悬停不是可以触发的正常事件。嘿。不,现在仍然如此nothing@David,对不起,您必须使用mouseover@NicolaPeluchetti,这对我电脑上的动画仍然不起作用side@David$(“#nav反射a”).hover(函数(){调用了吗?(在函数中放置警报以检查是否调用了)。在
play_ani()中放置警报。
是否调用了该函数?
function play(elem) {
    elem.stop().animate({ marginTop: "-10px" }, 200);
    elem.parent().find("span").stop().animate({ marginTop: "18px", opacity: 0.25 }, 200);

$("#nav-reflection a").hover(function() {
    play($(this));
}, function(){
    $(this).stop().animate({ marginTop: "0px" }, 300);
    $(this).parent().find("span").stop().animate({ marginTop: "1px", opacity: 1 }, 300);
});

setInterval(function() { play($("#nav-reflection a"); }, 5000);