将imsg src从一个更改为另一个表示“轻弹”
|
我有一张图片的img元素。例如:
<img id=\'imageWord\' src=images\\Card.png onclick=\'changeImage();\'>
当用户单击它时,我要进行一个淡出,将其src更改为另一张图像,然后淡出。
function changeImage()
{
$(\'#ImageWord\').animate({opacity:0})
.queue(function(){
$(this).attr(\"src\", \'\');
replaceImage(\'#ImageWord\', \'images\\newImage.png\');
$(this).dequeue()
})
.animate({opacity:1});
}
var MAX_HEIGHT = 260;
var MAX_WIDTH = 260;
function keepAspectRatio(temp, target, url)
{
$(target).removeAttr(\'style\');
// Get height and width once loaded
var realHeight = temp.height;
var realWidth = temp.width;
// Get how much to divide by (1 if image fits in dimensions)
// Get rid of \", 1\" if you just want everything to be either
// MAX_HEIGHT tall or MAX_WIDTH wide
var factor = Math.max(realHeight/MAX_HEIGHT, realWidth/MAX_WIDTH, 1);
realHeight /= factor;
realWidth /= factor;
// Set the target image\'s source, height and width
$(target).attr(\"src\", url).css({height: realHeight, width: realWidth});
if (realWidth != MAX_WIDTH)
{
var offsetX = (MAX_WIDTH - realWidth ) / 2;
var sum = parseFloat($(target).css(\"left\").replace(\"px\", \"\")) + offsetX;
$(target).css(\"left\", sum);
}
if (realHeight != MAX_HEIGHT)
{
var offsetY = (MAX_HEIGHT - realHeight) / 2;
var sum = parseFloat($(target).css(\"top\").replace(\"px\", \"\")) + offsetY;
$(target).css(\"top\", sum);
}
}
function replaceImage($target, url) {
$(\"<img>\").load(function() {
keepAspectRatio(this, $target, url);
}).attr(\"src\", url);
}
有时我看到以下内容:
Card.png淡出。
无图像(0.1秒)
再次使用Card.png(0.1秒)。
newImage.png fadeIn。
我想避免步骤3。
有什么建议吗?
没有找到相关结果
已邀请:
2 个回复
痰降锭骂奸
http://jquery.malsup.com/cycle/basic.html
嗓瑰