最新回答 / Jiaoguanwen
需要写括号,我的没加括号,它会直接判断为真,每次滚动滚动条就会加载很多,没有判断,视频里应该是老师忘记了,她的源码里有写,写不写我感觉是有区别的,因为我的这个一加括号就对了
2016-02-19
已采纳回答 / 耐斯兔米丘
var boxArr=new Array(), oElements=parent.getElementsByTagName('*');语句同时定义了boxArr和oElements两个变量
2016-02-17
//获取CSS样试里的值
function getStyle(obj,attr){
var ie = !+"\v1";//简单判断ie6~8
if(attr=="backgroundPosition"){//IE6~8不兼容backgroundPosition写法,识别backgroundPositionX/Y
if(ie){
return obj.currentStyle.backgroundPositionX +" "+obj.currentStyle.backgroundPositionY;
}
}
function getStyle(obj,attr){
var ie = !+"\v1";//简单判断ie6~8
if(attr=="backgroundPosition"){//IE6~8不兼容backgroundPosition写法,识别backgroundPositionX/Y
if(ie){
return obj.currentStyle.backgroundPositionX +" "+obj.currentStyle.backgroundPositionY;
}
}
function checkscrollside(){
var main=document.getElementById("main");
var boxs = main.getElementsByClassName("box");
var lastImgH = boxs[boxs.length-1].offsetTop + Math.floor(boxs[boxs.length-1].offsetHeight/2);
var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;//注意解决兼容性
var main=document.getElementById("main");
var boxs = main.getElementsByClassName("box");
var lastImgH = boxs[boxs.length-1].offsetTop + Math.floor(boxs[boxs.length-1].offsetHeight/2);
var scrollTop=document.documentElement.scrollTop||document.body.scrollTop;//注意解决兼容性
var minH=Math.min.apply(null,boxH);
var minHIndex=getminHIndex(boxH,minH);
boxs[i].style.position = "absolute";
boxs[i].style.top = (minH+marginLeft)+"px";
boxs[i].style.left=(boxs[minHIndex].offsetLeft-marginLeft)+'px';
boxH[minHIndex]+=boxs[i].offsetHeight+marginLeft;//更新添加了块框后的列高
}}}
var minHIndex=getminHIndex(boxH,minH);
boxs[i].style.position = "absolute";
boxs[i].style.top = (minH+marginLeft)+"px";
boxs[i].style.left=(boxs[minHIndex].offsetLeft-marginLeft)+'px';
boxH[minHIndex]+=boxs[i].offsetHeight+marginLeft;//更新添加了块框后的列高
}}}
var row_num = Math.floor(document.documentElement.clientWidth/boxW);
parent.style.cssText="width:"+boxW*row_num+"px;margin:0 auto;";
var boxH = new Array;
for(var i=0;i<boxs.length;i++){
if(i<row_num){
boxH.push(boxs[i].offsetHeight);//第一行不用考虑排列,先获取值
console.log(boxH[i]);
}else{
parent.style.cssText="width:"+boxW*row_num+"px;margin:0 auto;";
var boxH = new Array;
for(var i=0;i<boxs.length;i++){
if(i<row_num){
boxH.push(boxs[i].offsetHeight);//第一行不用考虑排列,先获取值
console.log(boxH[i]);
}else{
for(var i=0;i<dataInt.data.length;i++){ var box=document.createElement('div');
box.className='box'; main.appendChild(box); var img=document.createElement('img');
img.src='./images/'+dataInt.data[i].src; box.appendChild(img);
} rank('main','box'); }; }}
box.className='box'; main.appendChild(box); var img=document.createElement('img');
img.src='./images/'+dataInt.data[i].src; box.appendChild(img);
} rank('main','box'); }; }}
window.onload=function(){
rank('main','box');
var dataInt={'data':[{'src':'45.jpg'},{'src':'46.jpg'},{'src':'47.jpg'},{'src':'48.jpg'}]};
window.onscroll=function (){
if(checkscrollside()){
var main = document.getElementById('main');
rank('main','box');
var dataInt={'data':[{'src':'45.jpg'},{'src':'46.jpg'},{'src':'47.jpg'},{'src':'48.jpg'}]};
window.onscroll=function (){
if(checkscrollside()){
var main = document.getElementById('main');