简体   繁体   English

圆角与透明背景悬停效果

[英]rounded corners with transparent background hover effects

On my website, each menu button has it's corners rounded using the dd_roundies library, and has mouseover, mouseout, and onclick handlers assigned via JQuery. 在我的网站上,每个菜单按钮都使用dd_roundies库使其圆角,并具有通过JQuery分配的mouseover,mouseout和onclick处理程序。 The relevant JS code is: 相关的JS代码是:

$(function(){

    // Add an event handler to the menu items that changes the background colour on mouse-over
    // and reverts it on mouse-out.
    $('div.nav-box').hover(
      function() {
        $(this).addClass('highlight');
        document.body.style.cursor = 'pointer';
      }, 
      function() {
        $(this).removeClass('highlight');
        document.body.style.cursor = 'default';
      }
    );

    // Add an onclick handler to each menu item
    $('div.nav-box').click(
      function() {
        // Change the current page to the 'href' value of the nested <a> element
        document.location.href = $(this).find("a:first").attr("href");
      }
    );

    // Round the corners of the menu items 
    DD_roundies.addRule('.nav-box', '20px', true);
});

It all works very nicely in FF, but in IE7 it's a mess. 它在FF中运行得非常好,但在IE7中它是一团糟。 The most obvious problem is that the background that is applied on mouseover is square (not round), and on some occasions the background doesn't disappear after you click on on a menu item and then mouseout. 最明显的问题是鼠标悬停时应用的背景是方形(不是圆形),在某些情况下,单击菜单项然后单击鼠标后背景不会消失。

I don't expect anyone to figure out how to fix the code above, but if you know of an alternative way to: 我不希望有人弄清楚如何修复上面的代码,但如果你知道另一种方法:

  • apply transparent rounded corners to divs (such that the parent element's colour shows through the rounded corners) 将透明圆角应用于div(使得父元素的颜色通过圆角显示)
  • when the background colour of the rounded div is changed (eg by a mouseover event handler) the new background colour occupies the same round area 当圆角div的背景颜色改变时(例如,通过鼠标悬停事件处理程序),新的背景颜色占据相同的圆形区域
  • works in IE7 and FF3 (at least) 适用于IE7和FF3(至少)

In other words, make the menu referred to above work in IE as it does in FF. 换句话说,使上面提到的菜单在IE中工作,就像在FF中一样。 I'm open to replacing the existing JS libs with others, using CSS instead, or whatever..... 我愿意用其他人替换现有的JS库,而不是用CSS代替.....

Thanks, Don 谢谢,唐

I have had good luck using jQuery Corner for rounded corners in IE. 我在IE中使用jQuery Corner获取圆角很幸运。 I have tested it and it meets all your needs stated above. 我测试了它,它满足了上述所有需求。

$(document).ready(function(){
    $("div.nav-box").corner("20px");

    $("div.nav-box").click(function(){
        //
    });
});

I would also move any hover based style changes into a CSS. 我还会将任何基于悬停的样式更改移动到CSS中。 Although to get the hover to work in IE6 you will need to something like you have above. 虽然为了让悬停在IE6中工作,你需要像上面那样的东西。

div.nav-box
{
    cursor: default;
    background-color: Blue;
}

div.nav-box:hover
{
    cursor: pointer;
    background-color: Red;
}

I haven't tried this personally, but I believe that there's a method to get PNGs--which support alpha-layer transparency--to work in IE using HTML Components (.htc). 我没有尝试过这个,但我相信有一种方法可以使用HTML组件(.htc)在IE中使用支持alpha层透明度的PNG。 Check out this link . 看看这个链接

Using that .htc file, you should be able to use PNG background images to create anti-aliased rounded corners through CSS. 使用该.htc文件,您应该能够使用PNG背景图像通过CSS创建抗锯齿圆角。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM