如何用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圖像的來源? –
Lenny,請檢查我的JSFiddle http://jsfiddle.net/mNQ3R/提前致謝! – user1777158