我怎么知道什么是通过JavaScript显示的HTML部分 [英] how can i know what are the shown parts of the html through javascript

查看:75
本文介绍了我怎么知道什么是通过JavaScript显示的HTML部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取当前真正向用户显示的所有页面元素(仅限于浏览器框架内部的内容,而不是部分内容)高于或低于)。

例如,如果用户在页面中向下滚动,我想获取我的javascript其他元素。



我可以做到吗?如果没有,我可以从Chrome扩展程序中完成吗?

解决方案

试试

  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);


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?

解决方案

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);

这篇关于我怎么知道什么是通过JavaScript显示的HTML部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆