如何用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