Adding onto the recent Onmouseover and Onmouseout Event Monitoring Tutorial โฆ
- Simple Maths Timer Game
- Onmouseover and Onmouseout Monitor โฆ we add, today, a new โฆ
- Smooth Spinner Game
โฆ test of a userโs control, nerve and patience, where they need to hover (or click, for mobile devices) in consecutive order to maximise their score, that is also made up of a speed component to put dawdlers in their place โฆ ie. not nirvana.
Yes, non-mobile players will score better than mobile device players, because of the existence of an onmouseover (ie. hover) event. This same lament for mobile devices is a similar lament regarding a lot of Ajax functionality thoughts, which were very suited to making use of the onmouseover event.
With this game we can work in either โฆ
- Simple Maths Timer Gameโs table cell mode โฆ or โฆ
- Onmouseover and Onmouseout Monitorโs div element mode
โฆ and so it is really only the new scoring arrangements, and the changing of โbinaryโ H1 click toggling to โternaryโ (or more) select element selection, involved in thechanged mo_me_rt_thtm
dualternarypurpose live run link, today.
Before we leave this posting a coding approach weโd never used up until now got involved in the use of the new select (dropdown) element introduced. We gave โIDโ properties to all option sub-members to the select element. We also wanted to keep the traditional size=1 way of select elements (and always on mobile platforms), aware of not overusing height up the top of the webpage. The select element can serve a dual purpose here โฆ
- always show, in words, the other two modes of functionality, to help the user โฆ and this can be contained in that first option elementโs innerHTML property โฆ andโฆ
- the other two option elements can be rearranged value-wise and innerHTML-wise (they are always the same, for these two) for uniquifying option values, and at the end of the onchange logic โฆ
function stoggle(osel) {
var three=3, wasv='', newoi=' versus ', cs=['Simple Maths Timer Game','Onmouseover and Onmouseout Monitor','Smooth Spinner Game'], nv=osel.value;
if (osel.value != modeofgame) {
wasv=document.getElementById('myh1').innerHTML.split('&')[0].split('<')[0];
document.getElementById('soption').value=nv;
for (var ics=0; ics<cs.length; ics++) {
if (cs[ics] != nv) { if (newoi == ' versus ') { newoi+=cs[ics]; document.getElementById('o2').value=cs[ics]; document.getElementById('o2').innerHTML=cs[ics]; } else { newoi+=' or ' + cs[ics]; document.getElementById('o' + three).value=cs[ics]; document.getElementById('o' + three).innerHTML=cs[ics]; three++; } }
}
document.getElementById('soption').innerHTML=newoi;
document.getElementById('myh1').innerHTML=nv;
document.getElementById('stoggle').value=nv;
modeofgame=nv;
if (modeofgame == "Simple Maths Timer Game" && wasv != "Simple Maths Timer Game") { //"Onmouseover and Onmouseout Monitor") {
location.href=document.URL;
} else if (modeofgame == "Onmouseover and Onmouseout Monitor") {
divonl();
} else if (modeofgame == "Smooth Spinner Game") {
document.getElementById('score').innerHTML='';
document.getElementById('sofar').style.display='none';
document.getElementById('bclear').style.display='none';
document.getElementById('prebonus').style.display='none';
document.getElementById('bonus').style.display='none';
if (wasv == "Simple Maths Timer Game") {
document.getElementById('myq').style.fontSize='10px';
document.getElementById('mya').style.fontSize='10px';
document.getElementById('myq').innerHTML='Hover or Click<br> clockwise or anticlockwise';
document.getElementById('mya').innerHTML=' ... as fast<br> as you can ...';
}
}
}
}
โฆ always setting the select (dropdown) value equal to the first option value, and so always showing, in words, the full picture, for the user โฆ yoo hoo, you can wake up now!
Previous relevant Onmouseover and Onmouseout Event Monitoring Tutorial is shown below.
Perhaps you were reading yesterdayโs Maths Ouija Board Quiz Primer Tutorial and wondering โwhat gives with the โmo_me_rt_t.htmโ name of the web applicationโ? Well, the original inspiration at โMoving the mouse: mouseover/out, mouseenter/leaveโ, thanks, was for an Onmouseover and Onmouseout Event Monitor web application, and today we go back and add to โฆ
- Maths Ouija Board Quiz โฆ based on table cells โฆ to โฆ
- Onmouseover and Onmouseout Event Monitoring โฆ based on div elements โฆ
โฆ because nested hierarchical element arrangements like with HTML tables (with their cells) muddy the waters quite a bit trying to show the user a log also involving โฆ
These events are special, because they have property relatedTarget. This property complements target. When a mouse leaves one element for another, one of them becomes target, and the other one โ relatedTarget.
For mouseover:
event.target โ is the element where the mouse came over.
event.relatedTarget โ is the element from which the mouse came (relatedTarget โ target).
For mouseout the reverse:
event.target โ is the element that the mouse left.
event.relatedTarget โ is the new under-the-pointer element, that mouse left for (target โ relatedTarget).
โฆ and we want to mull over this, starting by logging event behaviour. We allow for an HTML h1 click/touch toggling of functionality, and we initially have the table cells show, but a toggling, maps over these table cells, position and all, with โฆ
- HTML divs โฆ
- CSS styled like table cells (ie. td) โฆ and using โฆ
- HTML table cell (ie. td) outerHTML property โฆ added with โฆ
- โoverlayโ favourites โฆ
- position:absolute property
- [HTML element].getBoundingClientRect() method to arrive with properties top, left, width, height (as we did with HTML map area subelements mapped to div when we presented Very Versus Too Game Primer Tutorial)
โฆ and โunderlayโ [HTML element].style.display=โnoneโ or [HTML element].style.visibility=โhiddenโ
See thechanged mo_me_rt_thtm dual
purpose live run link.
Previous relevant Maths Ouija Board Quiz Primer Tutorial is shown below.
Weโre not really using a ouija board with todayโs Maths Quiz web application, but if you use the mouse or trackpad means by which to answer the Maths arithmetic, it can feel like an ouija board in play.
Weโve arranged answers that just involve numbers so can have it that โฆ
- keyboard numbers can be interpreted as part of a userโs answer โฆ
- keyboard non-numbers can be interpreted as go check the answer โฆ
- onmouseover or onclick of number buttons are interpreted as part of a userโs answer โฆ
- onmouseover or onclick of โCheck Answerโ buttons go check the answer
The third of those above you may wonder about double ups. We left a setTimeout period of no doubling up between onmouseover and onclick event logics to help here.
Todayโs quiz scoring allows for bonus points for those quick to answer. The countdown of bonus points, as above, is achieved via a setTimeout timer.
Do you want to give todayโs HTML/Javascript/CSS mo_me_rt_thtm a go? We hope you do!
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.
If this was interesting you may be interested in this too.