jquery 또는 java 스크립트로 배경 이미지 onClick을 변경하려면 어떻게해야합니까?jquery 및 html5로 클릭시 배경 이미지 변경
예 : 여섯 개의 이미지가 있고 ">"(다음 화살표)를 클릭하고 "<"(뒤로 화살표)을 클릭하면 이전 배경 이미지로 변경하면 다음 배경 이미지로 변경하고 싶습니다. .
나는이 웹 사이트를 반응 형 html5 및 css3으로 개발 중입니다.
<script type="text/javascript" src="jquery-1.8.2.min.js"></script> //jquery inside the folder ok
<script type="text/javascript">
var images = ['url("../images/1366x768/image-_0107.jpg")', 'url("../images/1366x768/image-_0012.jpg")'], curIndex = 0; // here I set the images inside the desired folder
// Left arrow selector
$('.backarrow').click(function() { //here I set the back arrow "<"
if (curIndex > 0) {
// Container selector
$('backgrounds').css('../images/1366x768/image-0061.jpg', images[--curIndex]); // here I set my file backgrounds.css and the default image configured there
}
});
// Right arrow selector
$('.nextarrow').click(function() {
if (curIndex < images.length - 1) {
// Container selector
$('backgrounds').css('../images/1366x768/image-0061.jpg', images[++curIndex]);
}
});
</script>
<!--HTML 5 -->
<div id="square"><a href="" class="nextarrow">></a> <!-- here I call my jquery -->
</div>
<div id="square"><a href="" class="backarrow"><</a> <!-- here I call my jquery -->
</div>
/* CSS3 */
/* backgrounds.css */
body {
background: #dcd8d5 url(../images/1366x768/image-_0061.jpg) no-repeat center center fixed; -webkit-background-size: cover;
-moz-background-size: cover; -o-background-size: cover; background-size: cover }
/* default.css */
.nextarrow {
font-size:20px; color:#666; font-style:normal
}
.backarrow {
font-size:20px; color:#666; font-style:normal
}
내가 잘못 했습니까?
예, 고맙습니다. 거의이 스크립트가 배열의 이미지를 선택해야하므로 다음을 >> 클릭하면 배열의 다음 이미지로 이동하고 '이전을 클릭하면 이전 이미지로 이동하십시오. <<< – user1777158
배열에있는 것들, 모든 이미지의 ID 또는 bg 이미지의 소스? –
레니, 내 JSFiddle http://jsfiddle.net/mNQ3R/에 미리 감사하십시오! – user1777158