开发者

Enable/disable hover style at runtime?

In my css I have this:

#panel li:hover {
  background-color: #ffa;
}

under some condition I'd like to disable to hover style from the li items, something like:

function start() {
    $开发者_StackOverflow中文版('#panel li').ignoreHoverRules();
}

and re-enable it later:

function end() {
    $('#panel li').reenableHoverRules();
}

is something like that possible? Not sure how to 'enable' or 'disable' the hover style rules at runtime,

Thanks


Definitely the easiest way to do this is add a class to your <li> elements:

#panel li.allowHover:hover {
  background-color: #ffa;
}
function start() {
    $('#panel li').removeClass("allowHover");
}
function end() {
    $('#panel li').addClass("allowHover");
}

Otherwise, you get into very awkward territory with manipulating CSS rules - it's no easy task.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜