querySelector与getElementById怎么决解?
下面的是两个JS,麻烦给改改 谢谢。
<div class="top-img-1">
<div class=" top-img-sj-1"><p>打乱DIV1</p></div>
<div class=" top-img-sj-1"><p>打乱DIV2</p></div>
<div class=" top-img-sj-1"><p>打乱DIV3</p></div>
</div>
<!-- 引入内部JS -->
<script type="text/javascript">
// 将背景随机
window.onload=function(){
randomFun1();
}
// 轮播背景顺序打乱
function randomFun1(){
var container = document.querySelector('.top-img-1');
var itemArr = container.querySelectorAll('.top-img-sj-1');
var random = function(){return Math.random()>0.5 ? -1 : 1};
var itemArrShuffled = Array.from(itemArr).sort(random);
itemArrShuffled.forEach(function(item){
container.appendChild(item);
});
}
</script>
<div class="hhzp">
<div id="div1">
<a href="#" >A标签1</a>
<a href="#" >A标签2</a>
<a href="#" >A标签3</a>
</div>
</div>
<!-- 下面的JS本来是外部文件,为了方便这里就写在内部了 -->
<script>
window.onload = function() {
var oDiv = document.getElementById('div1');
var aA = oDiv.getElementsByTagName('a');
var i = 0;
for (i = 0; i < aA.length; i++) {
aA[i].pause = 1;
aA[i].time = null;
initialize(aA[i]);
aA[i].onmouseover = function() {
this.pause = 0;
};
aA[i].onmouseout = function() {
this.pause = 1;
};
}
setInterval(starmove, 80); /* 控制漂浮速度*/
function starmove() {
for (i = 0; i < aA.length; i++) {
if (aA[i].pause) {
domove(aA[i]);
}
}
}
function domove(obj) {
if (obj.offsetTop <= -obj.offsetHeight) {
obj.style.top = oDiv.offsetHeight + "px";
initialize(obj);
} else {
obj.style.top = obj.offsetTop - obj.ispeed + "px";
}
}
function initialize(obj) {
var iLeft = parseInt(Math.random() * oDiv.offsetWidth);
var scale = Math.random() * 1 + 1;
var iTimer = parseInt(Math.random() * 1500);
obj.pause = 0;
obj.style.fontSize = 12 * scale + 'px';
if ((iLeft - obj.offsetWidth) > 0) {
obj.style.left = iLeft - obj.offsetWidth + "px";
} else {
obj.style.left = iLeft + "px";
}
clearTimeout(obj.time);
obj.time = setTimeout(function() {
obj.pause = 1;
}, iTimer);
obj.ispeed = Math.ceil(Math.random() * 4) + 1;
}
};
</script>