我想知道如果jQuery的'这''可以简化我的代码吗?jQuery使用'this' - 缩略图交换图像,Twitter Bootstrap
这里的完整代码 http://bootsnipp.com/snippets/7ORr
感谢您的帮助,任何建议表示赞赏。
jQuery代码
/*
Ref: http://api.jquery.com/hover/
Calling $(selector).hover(handlerIn, handlerOut) is shorthand for:
$(selector).mouseenter(handlerIn).mouseleave(handlerOut);
*/
$(document).ready(function() {
$('.fd-fade1').hover(function() {
// img1
$('img.fd-img1').fadeIn('slow');
},
function() {
$("img.fd-img1").fadeOut("slow");
});
// img2
$('.fd-fade2').hover(function() {
$('img.fd-img2').fadeIn('slow');
},
function() {
$("img.fd-img2").fadeOut("slow");
});
// img3
$('.fd-fade3').hover(function() {
$('img.fd-img3').fadeIn('slow');
},
function() {
$("img.fd-img3").fadeOut("slow");
});
}); // end document.ready function
jQuery's'this'?你是什么意思?每个JS都有一个'this''变量“,它与jQuery无关。最好的改进可能是将相关元素的选择符存储在'data- *'属性中,然后使用'$($(this).data('related'))''来获得对它的引用。 –
是的,它可以......请发布HTML标记,而不是链接到bootsnipp – tymeJV