jQuery alternative for document.activeElement

What I wanted to do is figure out whenever the user is engaged with an INPUT or TEXTAREA element and set a variable flag to true... and set that flag to false immediately after the user is no longer engaged with them (ie. they've clicked out of the INPUT/TEXTAREA elements). I used jQuery's docuemnt.ready function to add the onclick attribute to my body element and assign it to my getAct

jQuery替代document.activeElement

我想要做的是计算出用户何时使用INPUT或TEXTAREA元素并将变量标志设置为true,并在用户不再使用它们后立即将该标志设置为false(即,已经点击了INPUT / TEXTAREA元素)。 我使用jQuery的docuemnt.ready函数将onclick属性添加到我的body元素并将其分配给我的getActive()函数。 getActive()函数的代码如下所示: function getActive() { activeObj = document.activeElement; var inFocus = false; if (activeObj.t

Click visible elements using puppeteer

I am trying to click a number of elements in in a page, but only if they are visible. This was quite easy using selenium (using is_displayed ), but I can't seem to find a way in puppeteer. I was trying to use something like try { await page .waitForSelector(id, visible=true, timeout=0) .then(() => { element.click() }); ... But this does not working if it i

点击可见元素使用木偶

我正在尝试点击页面中的多个元素,但前提是这些元素都可见。 这很容易使用硒(使用is_displayed ),但我似乎无法找到木偶的方式。 我正在尝试使用类似的东西 try { await page .waitForSelector(id, visible=true, timeout=0) .then(() => { element.click() }); ... 但是,如果它是一个简单的元素,这不起作用: <a class="cookie-close" href="#"> OK </a> 我似乎也无法

fade in/out div based on scroll

Ive seen a number of solutions that let you use scrolltop (which means you have to measure where the scroll is). Im wondering if it is possible to fade in/out a div, when it hits the screen or gets to the top of the screen/viewport? Cheers Ke Using JQuery: Detect bottom: $(window).scroll(function() { if($(window).scrollTop() + $(window).height() == $(document).height()) { alert

基于滚动淡入/淡出div

我看到了许多解决方案,可以使用滚动条(这意味着您必须测量滚动条的位置)。 我想知道是否可以淡入/淡出div,当它碰到屏幕或到达屏幕/视口的顶部时? 干杯 柯 使用JQuery:检测底部: $(window).scroll(function() { if($(window).scrollTop() + $(window).height() == $(document).height()) { alert("bottom!"); $("#divId").FadeIn("400") } }); 检测顶部: $(window).scroll(function() {

Stop video from loading in background on mobile

I have a video header that I only want to play on desktop, with a static image header on mobile. I can hide the video on mobile and it looks like it works fine, but the video is still being loaded in the background and slowing the page load. How can I stop the video from loading at all on mobile. <video id="bgvid" class="hidden-xs "> <source type="video/mp4" src="myvideo.mp4">

停止在移动设备上加载背景视频

我有一个视频头,我只想在桌面上播放,在手机上使用静态图像头。 我可以将视频隐藏在移动设备上,看起来效果不错,但视频仍在后台加载,并减慢了页面加载速度。 如何在移动设备上停止加载视频。 <video id="bgvid" class="hidden-xs "> <source type="video/mp4" src="myvideo.mp4"></source> </video> <img alt="" style="width: 100%; height: auto;" src="myimage.jpg" class="visible-x

CSS Change body margin size if an element is visible

I have a fixed position menu bar at the top of the page which is (lets say) 50px high, the body has a top margin of 50px also. Above the menu bar, there can be an error message which can vary in height. This variation means that the margin ontop of the body will need to change accordingly. I would like to avoid the use of javascript here but if it's not possible I will use it as a last re

CSS如果元素可见,则更改主体边距大小

我在页面顶部有一个固定的位置菜单栏(可以说)50px高,身体也有50px的顶部边距。 在菜单栏上方,可能会有一个错误消息,其高度可能会有所不同。 这种变化意味着身体的上边缘需要相应地改变。 我想避免在这里使用javascript,但如果这是不可能的,我会用它作为最后的手段。 http://subjectplanner.co.uk/Me/是该页面的一个例子。 如果你点击错误信息,它将消失,这就是页面的外观。 HTML代码: <div id="NavWrapper"

How can Selenium batch many isElementDisplayed calls?

Selenium has a convenient mechanism for pulling dozens or hundreds of elements from the DOM fairly efficiently and in a single fast round-trip: buttons = driver.find_elements_by_css_selector('button') The result buttons can be a list of dozens or hundreds of elements without any problem. But things slow to a crawl if you want to filter the elements using is_displayed() (or as Java calls it, i

Selenium如何批量许多isElementDisplayed调用?

硒有一个方便的机制,可以非常有效地从DOM中提取数十个或数百个元素,并且只需一次快速往返: buttons = driver.find_elements_by_css_selector('button') 结果buttons可以是几十或几百个元素的列表,没有任何问题。 但是如果你想用is_displayed()过滤元素(或者像Java调用它, isElementDisplayed ), isElementDisplayed事情就会慢慢爬行,因为每次调用该方法都需要往返于浏览器。 即使在我最快的开发机器上,每个这样的

Listen to element visibility in Angular 2

I'm using Bootstrap and Angular 2 (v4) for my webapp. I would like to listen to an element in a directive for visibility changes. My element has a parent that can hide its children with hidden-sm-up and I need to trigger a function each time it is hidden or displayed. div.hidden-sm-up input.form-control(myDirective, type='number') and in my directive: @Directive({ selector: '[myDi

收听Angular 2中的元素可见性

我为我的webapp使用Bootstrap和Angular 2(v4)。 我想倾听可见性更改指令中的元素。 我的元素有一个可以用hidden-sm-up隐藏它的子项的父项,并且每次隐藏或显示时都需要触发一个函数。 div.hidden-sm-up input.form-control(myDirective, type='number') 并在我的指示中: @Directive({ selector: '[myDirective]' }) export class myDirective { constructor(private element: ElementRef, private renderer:

Efficiently get an element's visible area coordinates

StackOverflow is loaded with questions about how to check if an element is really visible in the viewport, but they all seek for a boolean answer. I'm interested in getting the element's actual areas that are visible. function getVisibleAreas(e) { ... return rectangleSet; } Putting it more formally - the visible areas of elements is the set of (preferably non-overlapping) recta

高效地获取元素的可见区域坐标

StackOverflow加载了关于如何检查元素在视口中是否真的可见的问题,但他们都寻求布尔答案。 我有兴趣获取元素的可见区域。 function getVisibleAreas(e) { ... return rectangleSet; } 更正式地说 - 元素的可见区域是CSS坐标中的一组(最好是非重叠的)矩形,如果点(x,y)包含在其中,则elementFromPoint(x, y)将返回该元素(至少)集合中的一个矩形。 在所有DOM元素(包括iframe)上调用此函数的结果应该是一组

create if conditional based on css properties

This question already has an answer here: Check if element is visible in DOM 17 answers This is a way to determine it for all css properties including visibility: this works for properties set in a external css file, internal embedded styles, or inline styles! Note: the document MUST be loaded before executing the script! I have tested this out and it works with css rules set in inline, em

根据CSS属性创建条件

这个问题在这里已经有了答案: 检查元素在DOM 17答案中是否可见 这是一种确定所有css属性(包括可见性)的方法:这适用于在外部css文件,内部嵌入式样式或内联样式中设置的属性! 注意:必须在执行脚本之前加载文档! 我已经测试过了,它可以在嵌入,嵌入和外部设置的css规则下工作。 HTML: <div id="element" onload="test();">div content</div> CSS: #element { vi

how to rotate specific portion of the canvas

i have create the canvas which has different background and over that another image in the middle of canvas,now i want to rotate that image at 90 at its place only,i tried lots of code but get nothing as result. how can i do that..?? <style type="text/css" media="screen"> canvas, img { display:block; margin:1em auto; border:1px solid black; } canvas { background:url(http://i.daily

如何旋转画布的特定部分

我创建了具有不同背景和画布中间的另一个图像的画布,现在我只想在90处旋转该图像,我尝试了很多代码,但没有得到任何结果。 我怎样才能做到这一点..?? <style type="text/css" media="screen"> canvas, img { display:block; margin:1em auto; border:1px solid black; } canvas { background:url(http://i.dailymail.co.uk/i/pix/2013/11/11/article-2500617-007F32C500000258-970_306x423.jpg) } </sty