我有一个功能:

function test(e){
            $('.movie').find('.moreInfo').removeClass('moreInfoShow');
            e.parent().find('.moreInfo').addClass('moreInfoShow');
            $("#movieBox").isotope('reLayout');

            e.parent().find('.moreInfo').css("opacity", "0");
            e.parent().find('.moreInfo').animate({opacity: 1}, 500);
        }


称为:

$("#movieBox").on('mouseover', '.moviePoster', function(event){test($(this));});


问题是我希望在页面加载时调用该函数。我需要将“ this”传递给函数,但是我没有运气使其能够工作。

这是我期望的工作:

test($(".moviePoster").first());


(所有代码都在“ $(document).ready”函数中)

最佳答案

如注释中所述,在页面加载时触发mouseover事件。

$("#movieBox").find('.moviePoster').trigger('mouseover');


Reference

07-24 19:28