使用jQuery更改翻转时的图像源我有一些图片和他们的滚动图像。使用jQuery,当onmousemove/onmouseout事件发生时,我希望显示/隐藏滚动图像。我所有的图像名称都遵循相同的模式,如下所示:原始图像:Image.gif滚动图片:Imageover.gif我想插入并删除“完毕”在onmouseover和onmouseout事件中图像源的部分。我如何使用jQuery来完成它呢?
3 回答
慕村9548890
TA贡献1884条经验 获得超4个赞
$(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);
});});$(function() {
$("img")
.mouseover(function() {
var src = $(this).attr("src");
var regex = /_normal.svg/gi;
src = this.src.replace(regex,'_rollover.svg');
$(this).attr("src", src);
})
.mouseout(function() {
var src = $(this).attr("src");
var regex = /_rollover.svg/gi;
src = this.src.replace(regex,'_normal.svg');
$(this).attr("src", src);
});
});
慕容森
TA贡献1853条经验 获得超18个赞
#element {
width: 100px; /* width of image */
height: 200px; /* height of image */
background-image: url(/path/to/image.jpg);}#element:hover {
background-image: url(/path/to/other_image.jpg);}
繁星淼淼
TA贡献1775条经验 获得超11个赞
<img data-other-src="big-zebra.jpg" src="small-cat.jpg"><img data-other-src="huge-elephant.jpg" src="white-mouse.jpg"> <img data-other-src="friendly-bear.jpg" src="penguin.jpg">
$('img').bind('mouseenter mouseleave', function() {
$(this).attr({
src: $(this).attr('data-other-src')
, 'data-other-src': $(this).attr('src')
})});- 3 回答
- 0 关注
- 505 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消
