简体   繁体   中英

click on mobile/tablet, hover on other devices (future-proofing)

need an idea, I am stuck in quite the conundrum. I am building a responsive future proof webdesign.

On desktop and similar devices: I have a menu which on hover does a css animation to desplay a description of what hides behind the link and on click navigates to a new page.

On mobile devices: I wish to have a touch-event that triggers the hover (thus desplaying the description) and on touch number 2 it should then navigate to the new page.

the above is doable, but how to do it without checking user-agents, this is my situation. How does one go about future proofing the above.

Any great ideas are more then welcome. :)

Use Javascript to add a class on the touchstart / touchend events. Browsers won't issue these events:

Javascript:

document.querySelector("#myMenu").addEventListener("touchstart", function() {
    this.classList.add("mobileHovered ");
});
document.querySelector("#myMenu").addEventListener("touchend", function() {
    this.classList.remove("mobileHovered");
});

CSS:

#myMenu:hover,
#myMenu.mobileHovered {
    /* CSS styles */
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM