JSFiddle - React, Tailwind, and code Playground
HTML
<body onload="_l='t';">
<button id="b" data-pos="static">切换定位方式absolute</button>
<div>
<img src="http://www.webhek.com/wordpress/wp-content/uploads/2014/07/350.jpg?eefa26" id="i" style="position: static;">
</div>
<script>
var a = document.getElementById('i'),
b = document.getElementById('b');
b.addEventListener('click', doToggle, false);
function doToggle () {
if (b.getAttribute('data-pos') === 'absolute') {
a.style.position = 'static';
b.setAttribute('data-pos', 'static');
} else {
a.style.position = 'absolute';
b.setAttribute('data-pos', 'absolute');
}
}
</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() {
targetEl.style.webkitAnimationPlayState = 'paused';
}, __animationDuration, 'push');
}
else if(e.type == "animationstart" || e.type == "animationiteration") {
var targetEl = e.target;
setTimeout(function() {
targetEl.style.MozAnimationPlayState = 'paused';
}, __animationDuration, 'push');
...
CSS
img {
clip: rect(40px, 300px, 220px, 90px);
position: static;
}