Jquery check if element is visible in viewport

This question already has an answer here: Check if element is visible after scrolling 38 answers Well, how did you try to make it work? According to the documentation for that plugin, .visible() returns a boolean indicating if the element is visible. So you'd use it like this: if ($('#element').visible(true)) { // The element is visible, do something } else { // The element is

jquery检查元素在视口中是否可见

这个问题在这里已经有了答案: 滚动38个答案后,检查元素是否可见 那么,你是如何努力使它工作的? 根据该插件的文档, .visible()返回一个布尔值,指示该元素是否可见。 所以你会这样使用它: if ($('#element').visible(true)) { // The element is visible, do something } else { // The element is NOT visible, do something else } 检查元素在不带插件的视口中是否可见: 首先确定元素的顶部和底部位置

How to tell what fraction of element is inside viewport?

How to determine what percentage of a DOM element is inside the current viewport ? I want to calculate the ratio of area of element inside viewport and the total area of the element. Related question: How to tell if a DOM element is visible in the current viewport? See getBoundingClientRect and Window.innerHeight . let {top, height} = element.getBoundingClientRect(), percentVisible = Ma

如何判断元素的哪一部分在视口内?

如何确定当前视口内DOM元素的百分比是多少? 我想计算视口内元素的面积与元素的总面积之比。 相关问题:如何判断一个DOM元素在当前视口中是否可见? 请参阅getBoundingClientRect和Window.innerHeight 。 let {top, height} = element.getBoundingClientRect(), percentVisible = Math.max(0, Math.min(1, (window.innerHeight - top) / height)); 我在猜测你的用例,但在现代浏览器中,请参阅IntersectionObserver及

Converting HTML string into DOM elements?

This question already has an answer here: Creating a new DOM element from an HTML string using built-in DOM methods or Prototype 19 answers 您可以使用DOMParser ,如下所示: var xmlString = "<div id='foo'><a href='#'>Link</a><span></span></div>" , parser = new DOMParser() , doc = parser.parseFromString(xmlString, "text/xml"); doc.firstChild // => <d

将HTML字符串转换为DOM元素?

这个问题在这里已经有了答案: 使用内置的DOM方法或Prototype 19答案,从HTML字符串创建新的DOM元素 您可以使用DOMParser ,如下所示: var xmlString = "<div id='foo'><a href='#'>Link</a><span></span></div>" , parser = new DOMParser() , doc = parser.parseFromString(xmlString, "text/xml"); doc.firstChild // => <div id="foo">... doc.firstChild.firstChild /

Difference between load vs DOMContentLoaded

Possible Duplicate: Difference between DOMContentLoaded and Load events Whats the difference between window.addEventListener("load", load, false); and document.addEventListener("DOMContentLoaded", load, false); ? DOMContentLoaded - the whole document (HTML) has been loaded. load - the whole document and its resources (eg images, iframes, scripts) have been loaded. DOMContentLoaded a

负载与DOMContentLoaded之间的区别

可能重复: DOMContentLoaded和Load事件之间的区别 有什么区别 window.addEventListener("load", load, false); 和 document.addEventListener("DOMContentLoaded", load, false); ? DOMContentLoaded - 整个文档(HTML)已被加载。 load - 整个文档及其资源(例如图像,iframe,脚本)已被加载。 DOMContentLoaded仅等待HTML和要加载的脚本。 window.onload和iframe.onload会在页面完全加载所有相关资源(包括

when is window.onload fired

I'm a bit confused as to when the window.onload event is fired. For example: i have a page that has lots of external js files and even an on-demand loading of the script (dynamically creating a tag). All of this code is in the page (ie. it does not get fired on click or smth, it should execute while loading). Now let's say that i have window.onload = somefunction() in the last on-deman

当window.onload被解雇时

对于何时触发window.onload事件,我有点困惑。 例如:我有一个页面,有很多外部js文件,甚至按需加载脚本(动态创建标签)。 所有这些代码都在页面中(即,它不会在点击或不点击时被触发,它应该在加载时执行)。 现在让我们说,我有最后一个按需javascript的window.onload = somefunction()。 是否有可能在实际加载所有脚本之前,window.onload会触发? window.onload (aka body.onload )在主HTML,所有CSS,所有图像

Is $(document).ready() also CSS ready?

I've got a script executing on $(document).ready() that's supposed to vertically align block element in my layout. 90% of the time, it works without issue. However, for that extra 10% one of two things happens: There's an obvious lag in the time it takes to do the centering, and the block elements jump into position. This could simply be performance related - as the page size is

$(document).ready()也是CSS准备好了吗?

我有一个在$(document).ready()上执行的脚本,它应该在我的布局中垂直对齐块元素。 90%的时间,它的工作没有问题。 然而,对于额外的10%发生的两件事之一: 进行对中所需的时间明显滞后,并且块元素跳转到位。 这可能仅仅是与性能相关的 - 因为页面大小通常很大,并且有相当多的javascript一次执行。 居中将完全混乱,而块元素将推倒得太远或不够远。 看起来好像它试图计算高度,但得到不正确的测量。 为什么在D

Simplest way to detect a pinch

This is a WEB APP not a native app. Please no Objective-C NS commands. So I need to detect 'pinch' events on iOS. Problem is every plugin or method I see for doing gestures or multi-touch events, is (usually) with jQuery and is a whole additional pluggin for every gesture under the sun. My application is huge, and I am very sensitive to deadwood in my code. All I need is to detect a

最简单的方法来检测捏

这是一个WEB应用程序,不是原生应用程序。 请不要Objective-C NS命令。 所以我需要在iOS上检测'捏'事件。 问题在于我看到的用于做手势或多点触摸事件的每个插件或方法都是(通常)使用jQuery,并且是针对太阳下每个手势的整个附加插件。 我的应用程序非常庞大,我对代码中的死木非常敏感。 我需要的只是检测一个捏,并且使用像jGesture之类的东西只是让我满足简单需求的臃肿方式。 另外,我对如何手动检测夹点有

Catch browser's "zoom" event in JavaScript

Is it possible to detect, using JavaScript, when the user changes the zoom in a page? I simply want to catch a "zoom" event and respond to it (similar to window.onresize event). Thanks. There's no way to actively detect if there's a zoom. I found a good entry here on how you can attempt to implement it. I've found two ways of detecting the zoom level. One way to det

在JavaScript中捕获浏览器的“缩放”事件

当用户更改页面缩放时,是否可以使用JavaScript检测? 我只想捕捉一个“缩放”事件并对其作出响应(类似于window.onresize事件)。 谢谢。 没有办法主动检测是否有缩放。 我在这里找到了一个关于如何尝试实现它的好条目。 我发现了两种检测缩放级别的方法。 检测缩放级别更改的一种方法依赖于百分比值未缩放的事实。 百分比值与视口宽度有关,因此不受页面缩放的影响。 如果您插入两个元素,一个位置以百分比表示,另一

Getting table id

I am using jquery and my goal is to get the id of next table. I will simplify the code here: The simplified HTML looks like this: <div> <img src="png.png" class="exportIcon" alt='' onClick="tableExport()"> <table class="table tablesorter" id="tableHourlyT"><tr><td></td></tr></table> </div> And I then have the following function: &l

获取表格ID

我正在使用jquery,我的目标是获得下一个表的id。 我将在这里简化代码: 简化的HTML如下所示: <div> <img src="png.png" class="exportIcon" alt='' onClick="tableExport()"> <table class="table tablesorter" id="tableHourlyT"><tr><td></td></tr></table> </div> 然后我有以下功能: <script> function tableExport(){ tableID = $(t

get ID of this

I've written my own jQuery clicking function, but for an unkown reason, it doesn't work. I get error on line 4. for (var i = 1;i<=3;i++){ $("#Block"+i).click(function(){ $(this).effect("shake", function(){ if (this == "#Block3"){ window.open('contact.html','blank');//open link link in a new page } }); }); } Could you pl

得到这个ID

我写了自己的jQuery点击函数,但由于一个未知的原因,它不起作用。 我在第4行发生错误。 for (var i = 1;i<=3;i++){ $("#Block"+i).click(function(){ $(this).effect("shake", function(){ if (this == "#Block3"){ window.open('contact.html','blank');//open link link in a new page } }); }); } 你可以帮我吗? 说明 this第4行返回(或者是)