0

当您在我的 div 上“鼠标悬停”时,我会编写脚本以显示一些视频。因为 IE 我使用了调用 mouseenter 的 jquery 函数,但是什么也没发生。

我的脚本:

jQuery.fn.PlayMovieHome = function () {
    alert("something");
    var co = $(this).children("a").children("img").attr("src").split('images/')[1].split('.')[0];
    var odkaz = $(this).children("a").attr("href");
    $(this).children("a").after("<div id='video' style='position:absolute;width:163px;height:123px;top:5px;'><embed type='application/x-shockwave-flash' src='http://pacogames.com/games/videos/" + co + ".swf' width='163' height='123' wmode='transparent'></embed><a href='" + odkaz + "'><img src='http://pacogames.com/images/163x123.gif' style='position:absolute;left:0px;width:163px;height:123px;top:5px;'></a></div>");
};

jQuery.fn.StopMovieHome = function () {
    $(this).children('#video').remove();
};

和:

$("div#games").on('mouseenter', '.videobox', function () {
    var element = $(this);
    $(element).data('timeouthra', setTimeout(function () {
        $(element).PlayMovieHome();
    }, 250));
});

$("div#games").on('mouseleave', '.videobox', function () {
    var element = $(this);
    clearTimeout($(element).data('timeouthra'));
    $(this).StopMovieHome();
});

html看起来像这样:

<div id="games">
  <li id="videobox-id" class="videobox">
    <a href="/games/nascar.swf">    
    <img class="BOXGAMES_IMG" src="./images/nascar.png" alt="play nascar" style="position: relative; z-index: 1;" /><br />Nascar Racing
    </a>
  </li>
</div>

它不起作用。有人知道为什么吗?我错过了什么?

4

1 回答 1

1

尝试这个:

$("div#games").on('mouseenter', '.videobox', function () {
    var element = $(this);
    element.data('timeouthra', setTimeout(function () {
        element.PlayMovieHome();
    }, 250));
});

$("div#games").on('mouseleave', '.videobox', function () {
    var element = $(this);
    clearTimeout(element.data('timeouthra'));
    element.StopMovieHome();
});
于 2013-03-04T12:35:35.197 回答