JSFiddle - React, Tailwind, and code Playground
HTML
<body onload="_l='t';">
<div class="example" id="box" style="background: url(http://www.webhek.com/wordpress/wp-content/uploads/2014/07/200.jpg) 50% 50% / 50% no-repeat scroll content-box content-box rgb(127, 255, 212);"></div>
<button id="b" data-bg="true">切换新background属性值</button>
<script>
var i = document.getElementById('box'),
b = document.getElementById('b');
b.onclick = function () {
if (this.getAttribute('data-bg') === 'true') {
box.style.background = 'aquamarine url(http://www.webhek.com/wordpress/wp-content/uploads/2014/07/200.jpg) no-repeat scroll center center';
this.setAttribute('data-bg', 'false');
console.log("111");
} else {
console.log("222");
box.style.background = 'aquamarine url(http://www.webhek.com/wordpress/wp-content/uploads/2014/07/200.jpg) no-repeat scroll center center / 50% content-box content-box';
this.setAttribute('data-bg', 'true');
}
};
</script>
<script>
(function() {
setTimeout(function() {
// If onload hasn't been called, stop all requests after 2 seconds
if(typeof(_l) == 'undefined') {
if(window.stop !== undefined) window.stop();
else if(document.execCommand !== undefined) document.execCommand("Stop", false);
}
}, 2000, 'push');
/*
* Capture and kill CSS animations after X number of seconds
*/
function pauseAnimations() {
var body = document.getElementsByTagName('body')[0];
if(body.addEventListener) {
body.addEventListener("webkitAnimationStart", listener, false);
body.addEventListener("webkitAnimationIteration", listener, false);
body.addEventListener("animationstart", listener, false);
body.addEventListener("animationiteration", listener, false);
}
}
function listener(e) {
if(e.type == "webkitAnimationStart" || e.type == "webkitAnimationIteration") {
var targetEl = e.target;
setTimeout(function() {
...
CSS
.example {
box-sizing: border-box;
width: 220px;
height: 220px;
padding: 20px;
border: solid 1px black;
background: aquamarine url(http://www.webhek.com/wordpress/wp-content/uploads/2014/07/200.jpg) no-repeat scroll center center / 50% content-box content-box;
}