js实现照片墙功能实例(2)

var l2= obj2.offsetLeft;
                    var r2= l2+obj2.offsetWidth;
                    var t2= obj2.offsetTop;
                    var b2 =obj2.offsetHeight +t2;
                    if(b2<t1 || l2>r1 || r2<l1 || t2>b1){
                        return false;
                    }else{
                        return true;
                    }
                }
                //寻找最近的节点
                function nearLi(obj){
                    var index= -1;
                    var value =9999;
                   for(var i=0; i<len; i++){
                        if(isDump(obj,aLi[i]) && obj !=aLi[i]){
                            var c = getDis(obj,aLi[i]);
                            if(c <value){
                                value = c;
                                index = i;
                            }
                        }
                    }
                    if(index !=-1){
                        return aLi[index];
                    }else{
                        return false;
                    }
                }
                function getDis(obj1,obj2){
                    var x = obj1.offsetLeft - obj2.offsetLeft;
                    var y = obj1.offsetTop - obj2.offsetTop;
                    return  Math.sqrt(Math.pow(x,2)+Math.pow(y,2));
                }
            }
        </script>
    </head>
    <body>
    <button>click</button>
        <ul>
            <li><img src="https://www.jb51.net/article/1l.jpg"></li>
            <li><img src="https://www.jb51.net/article/2l.jpg"></li>
            <li><img src="https://www.jb51.net/article/3l.jpg"></li>
            <li><img src="https://www.jb51.net/article/4l.jpg"></li>
            <li><img src="https://www.jb51.net/article/5l.jpg"></li>
            <li><img src="https://www.jb51.net/article/6l.jpg"></li>
            <li><img src="https://www.jb51.net/article/1l.jpg"></li>
            <li><img src="https://www.jb51.net/article/2l.jpg"></li>
            <li><img src="https://www.jb51.net/article/4l.jpg"></li>
        </ul>
    </body> 
</html>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wgfxfp.html