javascript - Forcing mobile devices to activate :hover CSS properties on first touch and activate link on second touch -
: )
so, i'm trying solve hover effect issue. have tooltips on of links. code looks this:
<a href="https://wikipedia.org/wiki/space_shuttle_atlantis"> <h6 class="has-tip">space shuttle <p class="tip">the space shuttle invented santa claus</p> </h6> </a>
and css bit more involved:
.tip { display: block; position: absolute; bottom: 100%; left: 0; width: 100%; pointer-events: none; padding: 20px; margin-bottom: 15px; color: #fff; opacity: 0; background: rgba(255,255,255,.8); color: coal; font-family: 'ubuntu light'; font-size: 1em; font-weight: normal; text-align: left; text-shadow: none; border-radius: .2em; transform: translatey(10px); transition: .25s ease-out; box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28); } .tip::before { content: " "; display: block; position: absolute; bottom: -20px; left: 0; height: 20px; width: 100%; } .tip::after { /* lil triangle */ content: " "; position: absolute; bottom: -10px; left: 50%; height: 0; width: 0; margin-left: -13px; border-left: solid transparent 10px; border-right: solid transparent 10px; border-top: solid rgba(255,255,255,.8) 10px; } .has-tip:hover .tip { opacity 1; pointer-events auto; transform translatey(0px); }
now, on desktop works wonderfully. hover on tiny title , pretty looking tooltip, if click anywhere on title or tooltip (unless decide put yet link in paragraph works separately , nicely) activate link. yay : )
now on mobile, whole thing gets funky. touching activates link. if have slow internet, or ios, might glimpse tooltip next page loads.
i following behavior:
- user taps on tiny title (h6) has class (has-tip)
- if first tap, tooltip shows, , nothing else happens. 3)
- if tooltip showing when tap (as in subsequent tap) link activate , new page loads.
any ideas how might implement this? no jquery if possible.
one way save reference last clicked has-tip
link , apply class forces tip show. when click on link , matches the last 1 clicked, let event pass.
edit: oh, forgot mention might need classlist shim old ie.
html
<a href="http://jsfiddle.net/thepivottt/1tc52muq/1" class="has-tip"> jsfiddle<span class="tip">click fun recursion</span> </a><br /> <a href="http://google.com" class="has-tip"> google<span class="tip">click answers</span> </a>
js
lasttip = null; if(mobile) { var withtip = document.queryselectorall(".has-tip"); for(var i=0; i<withtip.length; ++i) { withtip[i].addeventlistener("click", function(e) { if(lasttip != e.target) { e.preventdefault(); if(lasttip) lasttip.classlist.remove("force-tip"); lasttip = e.target; lasttip.classlist.add("force-tip"); } }); } }
css
.has-tip { position: abolute; } .tip { display: none; position: relative; left: 20px; background: black; color: white; } .has-tip:hover .tip, .force-tip .tip { display: inline-block; }
Comments
Post a Comment