매개 변수를 함수에 전달하는 것과 관련된 다음 질문을 갖게되었습니다.올바른 자바 스크립트 함수를 코딩하여 코드 단순화
이 순간에 이루어집니다 방법 : 마우스를 유혹 할 때
나는 두 이미지 사이의 전환 효과를 가지고있다. 각 이미지의 경로가 다르므로 모든 이미지를 구분하기 위해 다른 클래스를 사용하므로 이미지 당 1 개의 함수가 필요합니다.
자바 스크립트 :
</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 : 내가 일하는 단지 1 자바 스크립트 기능을 구비하여이 작업을 단순화 할 수있는 방법 그래서 여기
.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;*/
}
내 질문은, 모든 이미지? 나는 함수에 전달 될 다음 나는 JQuery와의 CSS는 물건을 사용할 수있는 이미지의 경로를해야 이해하지만 좀 더 모르는 :)
이그래서 저를 도와주세요 :)
고맙습니다! 그것은 훌륭하게 작동하지만 더 많은 클래스를 가진 솔루션을 선호합니다. 그렇지 않으면 잠재적으로 20 개의 호출을 끝낼 수 있습니다 :) – nocrack