【发布时间】:2014-05-20 00:07:54
【问题描述】:
我有一个脚本可以在悬停时更改一些图像。效果很好,但是我想在两个图像之间添加一点淡入淡出。这是脚本。对 jQuery 来说真的很新,所以我有点困惑在哪里添加它。任何帮助将不胜感激
jQuery(document).ready(function ($) {
var img_src = "";
var new_src = "";
$(".rollover").hover(function () {
img_src = $(this).attr('src');
new_src = $(this).attr('rel');
$(this).attr('src', new_src);
$(this).attr('rel', img_src);
}, function () {
$(this).attr('src', img_src);
$(this).attr('rel', new_src);
});
//preload images
var cache = new Array();
//cycle through all rollover elements and add rollover img src to cache array
$(".rollover").each(function () {
var cacheImage = document.createElement('img');
cacheImage.src = $(this).attr('rel');
cache.push(cacheImage);
});
【问题讨论】:
标签: javascript jquery image fade