IE 9 resets background-position when hover (IE bug?)

大城市里の小女人 提交于 2019-12-12 15:03:03

问题


I can't bealieve i found something that works both in IE8 and IE7 but fails in IE9. Here is the page i was working on: [Link to the site][1]. Notice how in IE9, on the side menu when hover a link the browser resets the background to background-position: 0 0 and only after this applys, the script animates it to background-position: -20px 0 (where i want it to go in the first place). Is anything that i've done wrong or there is a IE bug? Also need some help to fix it.

here is the script that i am applaying to IE brawsers only:

**

  $('#nav_bar li')
.css( {backgroundPositionX:"-224px",
       backgroundPositionY:"0px"} )
.mouseenter(function(){
    $(this).stop().animate(
        {backgroundPositionX:"-20px"}, 
        {duration:550})
    })

.mouseleave(function(){
    $(this).stop().animate(
        {backgroundPositionX:"-224px",
        backgroundPositionY:"0px"}, 
        {duration:550})
    })

Thanks for the help!

[1]:


回答1:


Might I suggest the following CSS-only solution?

#nav_bar li {
    /* whatever you need for the background image */
    background-position: -224px 0;
    transition: background-position 0.55s ease;
    -webkit-transition: background-position 0.55s ease;
}
#nav_bar li:hover {
    background-position: -20px 0;
}

If you really want it to work in IE9 and below (since it does work fine in IE10), try animating backgroundPosition itself, rather than its component properties.

$("#nav_bar li")
 .css({backgroundPosition:"-224px 0"})
 .hover(
  function() {$(this).stop().animate({backgroundPosition:"-20px 0"},{duration:550});},
  function() {$(this).stop().animate({backgroundPosition:"-224px 0"},{duration:550});}
 );


来源:https://stackoverflow.com/questions/13994756/ie-9-resets-background-position-when-hover-ie-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!