首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Mouseout和mousedown冲突

Mouseout和mousedown冲突
EN

Stack Overflow用户
提问于 2013-06-11 15:09:36
回答 1查看 492关注 0票数 1

我想在table中,如果用户将鼠标放在用动画着色的每一行上,当鼠标移出时,行的颜色就会恢复为默认值。但是如果用户用鼠标右键单击行,该行将显示为红色,直到单击上下文菜单。

我尝试过此代码,但当用户右键单击并希望选择菜单项时,红色行返回到默认值,但我希望在单击( select )之前行为红色:

代码语言:javascript
复制
$(function () {
$('.users').contextMenu({
    selector: 'tr',
    callback: function (key, options) {
        if (key == 'delete') {
            if (confirm(" Are you sure?")) {
                $.post("../Actions/Delete.ashx", { type: "user", id: $(this).attr('id') });
                $(this).animate({ backgroundColor: '#FF80FF' }, 1000);
            }
        }

    },
    items: {
        "edit": { name: "edit" },
        "delete": { name: "delete" }
    }
});
$('tr').mouseover(function () {
    $('td', this).stop(true, true).animate
    ({ backgroundColor: "#80FF00" }, 300);
});

$('tr').mouseout(function () {
    $('td', this).stop(true, true).animate
    ({ backgroundColor: "white" }, 300);
});
$('tr').mousedown(function (event) {
    if (event.which==3) {
        $('td', this).animate
    ({ backgroundColor: "red" }, 300);
    }
});
});
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-11 18:36:18

使用clicked标志检查右键单击:

代码语言:javascript
复制
$(function () {
var clicked=false;
$('.users').contextMenu({
    selector: 'tr',
    callback: function (key, options) {
        if (key == 'delete') {
            if (confirm(" Are you sure?")) {
                $.post("../Actions/Delete.ashx", { type: "user", id: $(this).attr('id') });

                $(this).animate({ backgroundColor: '#FF80FF' }, 1000);
            }
        clicked=false;
        }

    },
    items: {
        "edit": { name: "edit" },
        "delete": { name: "delete" }
    }
});
$('tr').mouseover(function () {
    $('td', this).stop(true, true).animate
    ({ backgroundColor: "#80FF00" }, 300);
});

$('tr').mouseout(function () {
    if(!clicked){
    $('td', this).stop(true, true).animate
    ({ backgroundColor: "white" }, 300);
}
});
$('tr').mousedown(function (event) {
    if (event.which==3) {
        clicked=true;
        $('td', this).animate
    ({ backgroundColor: "red" }, 300);
    }
});
});
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17038367

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档