我有關於將參數傳遞給函數波紋管的以下問題。通過編寫適當的javascript函數來簡化我的代碼
它目前做的方式:
當鼠標懸停它我有兩個圖像之間的過渡效果。我需要每個圖像1個功能,因爲每個圖像的路徑不同,我使用不同的類來區分所有圖像。
的Javascript:
</script>
$(function() {
$(".fade_image1")
.find("span")
.hide()
.end()
.hover(function() {
$(this).find("span").stop(true, true).fadeIn();
}, function() {
$(this).find("span").stop(true, true).fadeOut();
});
});
$(function() {
$(".fade_image2")
.find("span")
.hide()
.end()
.hover(function() {
$(this).find("span").stop(true, true).fadeIn();
}, function() {
$(this).find("span").stop(true, true).fadeOut();
});
});
</script>
HTML:
<div>
<a href="#" class="fade_image1">Image<span></span></a>
</div>
<div>
<a href="#" class="fade_image2">Image<span></span></a>
</div>
CSS:
.fade_image1{
display: inline-block;
position: relative;
text-indent: -9999px;
width: 303px;
height: 605px;
background: url(images/20130128_UK_Colour-Campaign_cropped_02.jpg) no-repeat;
}
.fade_image1 span {
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
background: url(images/images-rollover/20130128_UK_Colour-Campaign_cropped-rollover_02.jpg) no-repeat;
/*background-position: -50px 0;*/
}
.fade_image2{
display: inline-block;
position: relative;
text-indent: -9999px;
width: 608px;
height: 302px;
background: url(images/20130128_UK_Colour-Campaign_cropped_03.jpg) no-repeat;
}
.fade_image2 span {
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
background: url(images/images-rollover/20130128_UK_Colour-Campaign_cropped-rollover_03.jpg) no-repeat;
/*background-position: -50px 0;*/
}
因此,這裏是我的問題,我怎樣才能通過只有1 javascript函數的工作簡化這個所有的圖像?我明白我需要的圖像的路徑傳遞到函數,然後我可以使用jQuery的CSS的東西,但我不知道更多:)
所以請幫我:)
謝謝!它工作得很好,但我更喜歡更多類的解決方案,因爲我可能最終會以20個電話結束,否則:) – nocrack