how can i know what are the shown parts of the html through javascript

筅森魡賤 提交于 2019-12-24 22:53:10

问题


I want to get all the href elements of the page that are really shown to the user in the current time (only what inside the browser frame, not the parts that above or under).

For example, if the user is scrolling down in the page, I want to get in my javascript other elements.

Can I even do it? And if not, can I do from Chrome extension?


回答1:


Try

var res = [];
$("a").each(function(i, el) {
  if (el.getBoundingClientRect().bottom <= window.innerHeight) {
    res.push($(el).eq(i));
    $(el).css({"color":"red", "border":"1px solid red"})
  };
});
console.log($("a").size(), res.length, res);


来源:https://stackoverflow.com/questions/25555960/how-can-i-know-what-are-the-shown-parts-of-the-html-through-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!