为 Daniel Nolan 的 img rollover javascript 添加淡入淡出过渡

发布于 2024-12-02 04:35:25 字数 721 浏览 0 评论 0原文

好吧,我已经意识到有很多关于使用 javascript 淡入淡出图像的东西,但它们都没有达到我想要的效果。

丹尼尔·诺兰确实如此。

他的脚本允许我简单地将 class=imgover 添加到图像中,结果是一个很好的图像交换。我所要做的就是制作第二张图像并在文件名末尾添加 _o 。这是我见过的最好、最简单的方法。我不需要花哨的 jQuery 转换,也不想通过添加 background 图像在 css 中添加额外的标记。我想要的只是图像之间的淡入淡出过渡。 相信我,我已经看过一些有关图像交换的 jQuery 图解。

我见过的所有 jQuery 图解都需要每个图像进行额外标记。我的页面上有几张图像需要图像交换。大多数在线评论都假设您只需要页面上的一张图像即可实现该效果。

如何向 Daniel Nolan 的 img rollover javascript 添加淡入淡出过渡?如果可能的话我想这样做,但我似乎无法让它发挥作用。

http://www.dnolan.com/code/js/rollover/

原始代码

Ok I have realized that there is a ton of stuff about fading images with javascript, but none of them do what I would like.

Daniel Nolan's DOES.

His script allows me to simply add class=imgover to an image, and the result is a nice image swap. All I have to do is make the second image and add _o at the end of the filename. This is the best and simplest way I've seen. I don't need fancy jQuery transitions and I don't want to add extra markup in my css by adding background images. All I want is a nice fade transition between the images. Trust me I've looked at several jQuery tuts on image swaps.

All of the jQuery tuts I've seen require extra markup per image. I have several images on my page that will need the image swap. Most tuts online assume you only need one image on the page that needs the effect.

How can I add a fade transition to Daniel Nolan's img rollover javascript? I'd like to do that if possible, but I can't seem to get it working.

http://www.dnolan.com/code/js/rollover/

Raw Code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

枫以 2024-12-09 04:35:25

你可以用纯 CSS3 做这样的事情,没有 Javascript...

HTML:

<div id="container">
    <div id="roll"></div>
    <div id="under"></div>
</div>

CSS:

#container {
    position:relative;
    width:50px; height:20px;
}
#roll {
    background:url('http://www.dnolan.com/code/js/rollover/rollover.gif');
    cursor:pointer;
    opacity:1;
    width:50px; height:20px;
    position:absolute; z-index:2;
    transition: all ease 2s;
    -moz-transition: all ease 2s;
    -webkit-transition: all ease 2s;
}
#roll:hover {
    opacity:0;
    transition: all ease 2s;
    -moz-transition: all ease 2s;
    -webkit-transition: all ease 2s;
}
#under {
    background:url('http://www.dnolan.com/code/js/rollover/rollover_o.gif');
    width:50px; height:20px;
    position:absolute; z-index:1;
}

演示

You could do something like this with pure CSS3, no Javascript...

HTML:

<div id="container">
    <div id="roll"></div>
    <div id="under"></div>
</div>

CSS:

#container {
    position:relative;
    width:50px; height:20px;
}
#roll {
    background:url('http://www.dnolan.com/code/js/rollover/rollover.gif');
    cursor:pointer;
    opacity:1;
    width:50px; height:20px;
    position:absolute; z-index:2;
    transition: all ease 2s;
    -moz-transition: all ease 2s;
    -webkit-transition: all ease 2s;
}
#roll:hover {
    opacity:0;
    transition: all ease 2s;
    -moz-transition: all ease 2s;
    -webkit-transition: all ease 2s;
}
#under {
    background:url('http://www.dnolan.com/code/js/rollover/rollover_o.gif');
    width:50px; height:20px;
    position:absolute; z-index:1;
}

Demo

晨光如昨 2024-12-09 04:35:25

这是最好的方法:

A better Implement of a fading image swap with javascript / jQuery

它与 Daniel Nolan 的前提相同脚本,但它有淡入淡出,而且是 jQuery。

This is the best way:

A better implementation of a fading image swap with javascript / jQuery

It has the same premise of Daniel Nolan's script but it has a fade and it's jQuery.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文