使用jQuery更改翻滚时的图像源 [英] Change the image source on rollover using jQuery
本文介绍了使用jQuery更改翻滚时的图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有几张图片和他们的翻转图像。使用jQuery,我想在onmousemove / onmouseout事件发生时显示/隐藏翻转图像。我的所有图像名称都遵循相同的模式,如下所示:
原图:
Image.gif $ c
$ bRollover Image:
Imageover.gif
我想分别在onmouseover和onmouseout事件中插入和移除图像源的over部分。
如何使用jQuery做到这一点? 要设置准备工作:
$(function(){
$(img)
.mouseover (function(){
var src = $(this).attr(src)。match(/ [^ \。] + /)+over.gif;
$(this ).attr(src,src);
})
.mouseout(function(){
var src = $(this).attr(src)。replace( );
$(this).attr(src,src);
});
});
I have a few images and their rollover images. Using jQuery, I want to show/hide the rollover image when the onmousemove/onmouseout event happen. All my image names follow the same pattern, like this:
Original Image:
Image.gif
Rollover Image:
Imageover.gif
I want to insert and remove the "over" portion of image source in the onmouseover and onmouseout event, respectively.
How can I do it using jQuery?
解决方案
To set up on ready:
$(function() {
$("img")
.mouseover(function() {
var src = $(this).attr("src").match(/[^\.]+/) + "over.gif";
$(this).attr("src", src);
})
.mouseout(function() {
var src = $(this).attr("src").replace("over.gif", ".gif");
$(this).attr("src", src);
});
});
这篇关于使用jQuery更改翻滚时的图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文