Well, you can do this using jQuery
or javaScript
. The basic idea would be to toggle the class of the body
tag. See an example below :
JavaScript Solution :
HTML:
<body>
<div style="color:red;">Some random text here</div>
<input type="button" id="btnBack" value="Toggle Background" />
</body>
CSS:
body {
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed
}
.BgClass {
background-image: url('http://freedomwallpaper.com/wallpaper2/funky-wallpaper-hd.jpg');
}
javaScript
var btnBack = document.getElementById('btnBack');
btnBack.addEventListener('click',function() {
document.body.classList.toggle('BgClass');
});
You can see this here -> http://jsfiddle.net/qagdvft6/
jQuery Solution
$('#btnBack').click(function() {
$('body').toggleClass('BgClass');
});
body{
background-size: cover;
background-repeat: no-repeat;
background-attachment: fixed
}
.BgClass {
background-image: url('http://freedomwallpaper.com/wallpaper2/funky-wallpaper-hd.jpg');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<body>
<div style="color:red;">Some random text here</div>
<input type="button" id="btnBack" value="Toggle Background">
</body>