会员可以在此提问,百战程序员老师有问必答
对大家有帮助的问答会被标记为“推荐”
看完课程过来浏览一下别人提的问题,会帮你学得更全面
截止目前,同学们一共提了 132358个问题
WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 241楼
WEB前端全系列/第二阶段:JavaScript编程模块/运算符_数据类型和流程循环语句 243楼
WEB前端全系列/第二阶段:JavaScript编程模块/面向对象编程 245楼

function waterFlow(){
    var parentconter = document.getElementById("conter");  
    var allChild = document.getElementById("conter").getElementsByClassName("boximg");
    var screenWidth = document.documentElement.clientWidth;
    var childWidth = allChild[0].offsetWidth;
    var rowsNum = Math.floor(screenWidth/childWidth)-1;
    parentconter.style.cssText="width:"+rowsNum*childWidth+"px;margin: 0 auto;"

    getMinHeightOfCols(allChild,rowsNum)
}
waterFlow()

// 动态设置图片位置
function getMinHeightOfCols(allChild,rowsNum){
    // 存储每列高度
    var colsHeightArr = [];
    for(var i =0;i<allChild.length;i++){
        //判断取出第一行的图片,获取图片对应高度,放入到数组中 
        if(i<rowsNum){
           //获取当前图片高度
           colsHeightArr[i] = allChild[i].offsetHeight;
        //    console.log(colsHeightArr[i])
        }else{
            //获取高度最小的值
            var minHeightofCols = Math.min.apply(null,colsHeightArr);
            // console.log(minHeightofCols)
            //获取最小值对应的下标(位置)
            var minHeightOfIndex = colsHeightArr.indexOf(minHeightofCols);
            console.iog(minHeightOfIndex)
            //摆放第二列图片位置
            allChild[i].style.position = "absolute";
            allChild[i].style.top=minHeightOfCols+"px";
            allChild[i].style.left=allChild[minHeightOfIndex].offsetleft+"px";
            colsHeightArr[minHeightOfIndex] = colsHeightArr[minHeightOfIndex] + allChild[i].offsetHeight;
        }
    }
}

下标位置获取不到,无法添加定位样式

WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 247楼
WEB前端全系列/第二阶段:JavaScript编程模块/字符串与数组 248楼

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            height: 2000px;
       background: linear-gradient('skyblue','pink');
       
        }
    </style>
</head>
<body>
    <span>密码:</span><input type="password"><span class="passwordSpan"></span>
   
    <script>
        var password=document.querySelector('input');
        var passwordSpan=document.querySelector('.passwordSpan');
        var flag=false;
       
        // document.body.onkeydown=function(){
        //     if(event.keyCode==20){
        //         flag=!flag;
        //     }
        //     if(flag){
        //         passwordSpan.innerHTML='现在是大写';
               
        //     }else{
        //      passwordSpan.innerHTML='现在是小写'
        //     }
        // }
        // document.body.onkeydown=function(){
        //     if(event.keyCode==40){
        //         window.onscroll=function(){
        //              var top=document.body.scrollTop||document.documentElement.scrollTop;
                   
        //         top=top-500;
        //         document.body.scrollTop=top;
        //         document.documentElement.scrollTop
        //         console.log(document.body.scrollTop||document.documentElement.scrollTop);
        //         }
               
        //     }
        //     if(event.keyCode==38){
        //         window.onscroll=function(){
        //              var top=document.body.scrollTop||document.documentElement.scrollTop;
        //         top=top+500;
        //         document.body.scrollTop=top;
        //         document.documentElement.scrollTop;
        //         console.log(document.body.scrollTop||document.documentElement.scrollTop);
        //         }
               
        //         }
        //     }
      window.onscroll=function(){
        console.log("top"+document.documentElement.scrollTop||document.body.scrollTop);
      }

        window.onkeydown=function(){
            console.log(event.keyCode);
            if(event.keyCode==65){
                var top=document.documentElement.scrollTop||document.body.scrollTop;
                top-=100;
                document.documentElement.scrollTop=top;

                document.body.scrollTop=top;
             
            }
            if(event.keyCode==68){
                var top=document.documentElement.scrollTop||document.body.scrollTop;
                top+=100;
                document.documentElement.scrollTop=top;

                document.body.scrollTop=top;
             
            }
        }
    </script>
</body>
</html>

老师 系统自带箭头滚动功能怎么搞 我设置了上箭头向上滚动200  还是2 来滚动

WEB前端全系列/第二阶段:JavaScript编程模块/浏览器模型(BOM) 253楼
WEB前端全系列/第二阶段:JavaScript编程模块/DOM模型 255楼

课程分类

百战程序员微信公众号

百战程序员微信小程序

©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园
网站维护:百战汇智(北京)科技有限公司
京公网安备 11011402011233号    京ICP备18060230号-3    营业执照    经营许可证:京B2-20212637