使用悬停来交换图像,如果我在“.this_page”上,我不想交换图像
当我登陆页面时,另一个函数(未显示,工作正常)将适当的导航类设置为“.this_page”,然后我滚动,图像正确交换,但是当我悬停并离开“img.”时,图像会正确交换。当我第二次悬停时,this_page' 它会交换。我不希望它“img.this_page”交换。我尝试解除鼠标悬停的绑定,但在悬停时显然它会重新绑定......所以每次您悬停时,它都会重置。
页面位于 http://flourgarden.com/wp/
这是我的功能:
function hoverNavs() {
var baseURL='http://www.flourgarden.com/wp/wp-content/themes/flourgarden/images/nav';
var cache=[];
$j('.lcolumn a img').each(function() {
var t = $j(this);
var src1 = t.attr('src'); // initial src
var newSrc = src1.substring(src1.lastIndexOf('/'), src1.lastIndexOf('.')); // let's get file name without extension
i = baseURL+newSrc+'_select.png';
cache.push(i);
t.hover(function(){
$j(this).attr('src', baseURL+newSrc+ '_select.' + /[^.]+$/.exec(src1)); //last part is for extension
}, function(){
if($j(this).class == "this_page") {
$j(this).attr('src', baseURL+newSrc+ '_select.' + /[^.]+$/.exec(src1));
} else {
$j(this).attr('src', baseURL+newSrc+ '.' + /[^.]+$/.exec(src1));
}
});
});
}
When I land on the page, another function (not shown, that works fine) sets the class of the appropriate nav to '.this_page' and then I roll over, and the images swap correctly, but when I hover and leave 'img.this_page' it swaps, the second time I do the hover. I don't want it 'img.this_page' to swap. I tried unbinding mouseout, but on hover apparently it rebinds... so each time you hover, it resets.
Page is at http://flourgarden.com/wp/
Here's my function:
function hoverNavs() {
var baseURL='http://www.flourgarden.com/wp/wp-content/themes/flourgarden/images/nav';
var cache=[];
$j('.lcolumn a img').each(function() {
var t = $j(this);
var src1 = t.attr('src'); // initial src
var newSrc = src1.substring(src1.lastIndexOf('/'), src1.lastIndexOf('.')); // let's get file name without extension
i = baseURL+newSrc+'_select.png';
cache.push(i);
t.hover(function(){
$j(this).attr('src', baseURL+newSrc+ '_select.' + /[^.]+$/.exec(src1)); //last part is for extension
}, function(){
if($j(this).class == "this_page") {
$j(this).attr('src', baseURL+newSrc+ '_select.' + /[^.]+$/.exec(src1));
} else {
$j(this).attr('src', baseURL+newSrc+ '.' + /[^.]+$/.exec(src1));
}
});
});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用
not
过滤函数来排除“.this_page”吗?Is the
not
filter function what you need to exclude '.this_page'?