请查看我的codepen交易:http://codepen.io/githubmaht/pen/jinHo
function getRandomInt (min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
var wrapper = document.createElement('wrapper');
wrapper.className = 'wrapper';
wrapper.style.cssText = "display:block;position:relative;height:100%;width:100%;";
document.body.appendChild(wrapper);
var bigholdery = document.createElement('bigholdery');
bigholdery.className = 'bigholdery';
bigholdery.style.cssText="display:block;position:absolute;left:0;top:0;height:50%;width:50%;overflow:auto;";
document.getElementsByClassName('wrapper')[0].appendChild(bigholdery);
// green bars!!!
var big = document.createElement('big');
big.className = 'big';
big.style.cssText="display:block;position:relative;height:300em;background-image: -webkit-gradient(linear, 0 0, 0 100%, color-stop(.5, green), color-stop(.5, transparent), to(transparent));-webkit-background-size: 6em 6em;";
document.getElementsByClassName('bigholdery')[0].appendChild(big);
// make one red!!!
var redoffset = 3*getRandomInt(0,49);
var red = document.createElement('red');
red.className = 'red';
red.style.cssText="font-size:12px;display:block;position:absolute;top:0;left:0;height:3em;width:100%;background:red;margin-top:"+redoffset+"em;";
document.getElementsByClassName('bigholdery')[0].appendChild(red);
CSS ----->
html{
position:relative;
height:100%;
width:100%;
font-size:12px;
}
body{
position:relative;
height:100%;
width:100%;
background:#BEDFED;
}
.wrapper {
position:relative;
display:block;
height:100%;
}
答案 0 :(得分:1)
你的绿色渐变实际上是300em。请在代码中查看此行:
big.style.cssText="display:block;position:relative;height:300em;