English 中文(简体)
如何淡入jquery中背景图像的背景位置更改?
原标题:How To Fade In A background-position change for a background image in jquery?

我正在使用一个巨大的精灵作为一个元素,在悬停时改变不同的状态。我想知道是否有办法让悬停状态的图像淡入?您可以实时查看我的代码-此处

以下是我针对每个跨度的悬停状态的代码

$(".hf-1").hover(
        function () {
                $(this).css("background-position","0 -121px");
                $(".hf-2").css("background-position","0 -242px");
                $(".hf-3").css("background-position","0 -363px");
                $(".hf-4").css("background-position","0 -484px");
              },
        function () {}

);

我使用Jquery来做背景图像悬停,而不是基本的css,因为我有多个悬停需要重置。

谢谢你的帮助。

问题回答

使用以下内容:

$(this).animate({"background-position": "0 -121px"}, "slow");

冲洗并重复其他三个步骤。

你需要将背景叠加两次,然后从另一个渐变。无法在同一个容器中淡入。

或者您可以只使用jquery的本机fadeIn API。

 $(this).click(function () {
            $("this").fadeIn("slow");
          });




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签