I need to run the hover pseudo-class programmatically (if possible, with bubbles, or I will be forced to cause a change for all elements of the parents too). I have no control over the html page, so I can not change css from: hover to .hover in order to upgrade the HTMLElement class to .hover.
Is it possible?
Please, NO HEALTH. I can not use jQuery in my project.
Thanks in advance.
UPDATE
I created a proxy server for loading CSS, so before downloading css it goes to my "proxy", which changes the rules: from hover to .hoverclass.
Well, now the freeze effects work very well, but I have a serious performance issue due to the bubbling freeze simulation.
Here is the code:
var actualHoveredElements = new Array(); var hoverAddedCount = 0; var maxHoveredElems = 5; function changeHover(newElement, oldElement){ var oldHoveredElements = actualHoveredElements.slice(); var remainingElements = setHoverForParentsOfElement(newElement, oldHoveredElements); for(var i = 0; i < remainingElements.length; i++){ var notHoveredElement = remainingElements[i]; var actualIndex = actualHoveredElements.indexOf(notHoveredElement); if(actualIndex > -1){ actualHoveredElements.splice(actualIndex, 1); } notHoveredElement.classList.remove("hoverclass"); } hoverAddedCount = 0; changeHoverTimeout = null; } function setHoverForParentsOfElement(element, oldHoveredElements){ var index = -1; if(oldHoveredElements != "undefined" && oldHoveredElements.length > 0) index = oldHoveredElements.indexOf(element); if(index > -1){ oldHoveredElements.splice(index, 1); } else { actualHoveredElements.push(element); element.classList.add("hoverclass"); } if(element.tagName != "BODY" && element.tagName != "HTML"){ if(hoverAddedCount < maxHoveredElems-1){ hoverAddedCount ++; oldHoveredElements = setHoverForParentsOfElement(element.parentNode, oldHoveredElements); } } return oldHoveredElements; }
As you can see, I also tried to limit the number of freezes imposed on N, but the performance issue still exists.
javascript css
Giuseppe lanza
source share