jQuery hover fadeIn淡出问题
jQuery hover fadeIn fadeOut problem
我刚刚回到html, javascript和jquery,我有点生疏。我用objective-c已经有一段时间了,回到jquery有点困难。我试图使用jQuery的fadeIn和fadeOut位,但它不工作的某种原因…这是我一直在做的html和js:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.3.min.js">
function showImg(2img) {
$(2img).fadeIn('slow', function() {
// Animation complete
});
}
function hideImg(2img) {
$(2img).fadeOut('slow', function() {
// Animation complete
});
}
</script>
<body>
<table width="1659" height="701" border="0" align="center">
<tr>
<th width="325" scope="col"><div style="position: relative; left: 0; top: 0;"><img id="img1" src="" width="232" height="232" alt="" onmouseover="showimg(2img1)" onmouseout="hideimg(2img1)" style="position: relative; top: 0; left: 0;"/>
<img id="2img1" src="" width="32" height="32" alt="" style="position: absolute; top: 100px; left: 150px; visibility:hidden;"/></div></th>
<th width="325" scope="col"><div style="position: relative; left: 0; top: 0;"><img id="img2" src="" width="232" height="232" alt="" onmouseover="showimg(2img2)" onmouseout="hideimg(2img2)" style="position: relative; top: 0; left: 0;"/>
<img id="2img2" src="" width="32" height="32" alt="" style="position: absolute; top: 100px; left: 150px; visibility:hidden;"/></div></th>
<th width="325" scope="col"><div style="position: relative; left: 0; top: 0;"><img id="img3" src="" width="232" height="232" alt="" onmouseover="showimg(2img3)" onmouseout="hideimg(2img3)" style="position: relative; top: 0; left: 0;"/>
<img id="2img3" src="" width="32" height="32" alt="" style="position: absolute; top: 100px; left: 150px; visibility:hidden;"/></div></th>
<th width="325" scope="col"><div style="position: relative; left: 0; top: 0;"><img id="img4" src="" width="232" height="232" alt="" onmouseover="showimg(2img4)" onmouseout="hideimg(2img4)" style="position: relative; top: 0; left: 0;"/>
<img id="2img4" src="" width="32" height="32" alt="" style="position: absolute; top: 100px; left: 150px; visibility:hidden;"/></div></th>
<th width="325" scope="col"><div style="position: relative; left: 0; top: 0;"><img id="img5" src="" width="232" height="232" alt="" onmouseover="showimg(2img5)" onmouseout="hideimg(2img5)" style="position: relative; top: 0; left: 0;"/>
<img id="2img5" src="" width="32" height="32" alt="" style="position: absolute; top: 100px; left: 150px; visibility:hidden;"/></div></th>
</tr>
</table>
</body>
我想你会发现这样做更好:
$(function() {
$('table > div > img:first').hover(function() {
showImg($(this).next());
}, function() {
hideImg($(this).next());
});
});
这样你就不会在你的html中复制onmouseover和onmouseoout代码。
你的代码中的错误是-没有#图像的id褪色,虽然它似乎在chrome中工作,我不知道它是否会在每个浏览器中按预期工作,函数名称也没有相同的情况。
$(2img)
应该是$('#2img')
,就这样
$(2img)应该是$('#'+2img),并且调用类似showImg("2img2")的函数
DEMO
$('.tb td').each(function(){
$(this).find('img').wrapAll('<div />');
$('.tb td div').css({position:'relative'});
$(this).find('img:eq(1)').css({position:'absolute', left:'0px', top:'0px'}).hide();
});
$('.tb td div').hover(function(){
$(this).find('img:eq(1)').stop().fadeTo(400,1);
},function(){
$(this).find('img:eq(1)').stop().fadeTo(400,0);
});
相关文章:
- 我的流星路线出了什么问题
- 空函数似乎从包装器中清除了一些类,但不是全部.试图找出问题所在
- 电话间隙没有互联网警报弹出问题
- 从不同选项卡打开时出现Javascript弹出问题
- IE 中的 Javascript window.close() 弹出问题
- 完整日历弹出问题
- 模态弹出问题
- 在angular js中向控制器注入常量(模式弹出问题)
- Facebook登录弹出问题
- Knockout-弹出问题编辑项目
- 解决浏览器弹出问题
- chrome新版本37中的弹出问题
- phanttomjs:绝对路径工作,但相对路径给出问题
- Javascript滑出问题
- 需要帮助解决模态弹出问题
- iPad Safari弹出问题
- 鼠标输入/离开&鼠标悬停/移出问题
- 弹出问题..不确定这是否是最好的方法
- Javascript/jQuery函数在鼠标移到/移出时淡出
- IE中的JQuery弹出问题