Get real position of objects in Javascript with Chrome

前端 未结 3 1372
自闭症患者
自闭症患者 2021-01-24 04:12

I\'ve been coding a bit of Javascript to place a ducky randomly on this page.

I wanted to make it hide on the side of objects (like the posts), but I ended up having to

3条回答
  •  终归单人心
    2021-01-24 04:29

    Alright, my problem was somewhere else. This is what I was doing to call the function:

    var allPosts = document.getElementsByClassName('post-outer');
    
    for (post in allPosts) {
       console.log('Post has position '+getPos(post));
    }
    

    You can tell I'm not so used to Javascript's recursive behavior in the for loop, so the following code actually fixes my issue:

    var allPosts = document.getElementsByClassName('post-outer');
    
    for (var i=0, len=allPosts.length; i

    Thanks all for your help :-)

提交回复
热议问题