javascript - Add CSS change on touch start for mobile devices -
i'm attempting change css of link before app navigates page. i've added ontouchstart
event link element speed navigation in app. problem event fires , app navigates before css can change.
what ways provide user feedback before page changes?
additional notes:
- this spa constructed using angularjs , phonegap build.
- i discovered using
button:active
fire after button clicked page navigate before css changes. - i believe need tested on touch-screen device see effect.
- this first question on here please gentle :)
here example code:
html
<a class="button" ontouchstart="goto('#!/stats', 'buttonactive', this);" onclick="goto('#!/stats', 'buttonactive', this);">stats</a>
css
.button { display: flex; background-color: #000000; color: dodgerblue; font-size: 4vmin; cursor: pointer; text-decoration: none; font-size: 7vmin; border: 0.75vmin solid dodgerblue; border-radius: 1vmin; height: 8vh; width: 40vmin; padding: 2vmin; margin: 5vmin auto; align-items: center; justify-content: center; } .buttonactive { background-color: dodgerblue; color: white; }
js
function goto (location, addclass, elem) { elem.classname += addclass; window.location.href = location; }
you add slight delay goto function's window.location.href call. give css time update before new file requested. might this:
function goto (location, addclass, elem) { elem.classname += addclass; settimeout(function(){ window.location.href = location; }, 250); }
that make 250-millisecond delay...likely enough time allow css update , viewers recognize change before new file request initiated.
Comments
Post a Comment