PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Sat Oct 21, 2017 3:29 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Fri Feb 03, 2017 7:19 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4349
Location: United Kingdom
I'm learning as I go with this sort of stuff.
I don't know how to add a "touchstart event listener".
:hover works on some mobiles, as it adapts to use it via a tap, except Android. Tho logically, it shouldn't work on mobile at all.
So how do I code what you have described?
As you can see, this is needed for the main dropdown, but also the Category dropdowns too.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Fri Feb 03, 2017 7:26 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6573
Location: WA, USA
Main, category, works the same way.

No Javascript framework means you'll have to do this all manually, which sucks. Consider using one.

Start by finding all the menu elements that you'll want to expand. querySelectorAll should get you pretty far.
Then for each element in the list that it returns you use addEventListener with touchstart
Code:
.addEventListener("touchstart", function(e) {

Inside that callback function you'll have "this" as whatever element. Apply the logic I said to switch class names, and if you need to remove it from other menu items (recommended) then querySelector can find you the currently open menu (if there is one).


Top
 Profile  
 
PostPosted: Fri Feb 03, 2017 7:28 am 
Offline
DevNet Master

Joined: Wed Oct 08, 2008 3:39 pm
Posts: 4349
Location: United Kingdom
Can you show me a short 'fiddle' version of what you are getting at?
I've looked at that page, but I no zero about that sort of code, so to do the rest of what you have described, it's not in my power!

If I see an example, I can get my head around it, and see what's what.

_________________
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.


Top
 Profile  
 
PostPosted: Fri Feb 03, 2017 7:48 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6573
Location: WA, USA
Take a read through MDN's event guide. In the meantime I need to eat.


Top
 Profile  
 
PostPosted: Fri Feb 03, 2017 8:59 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6573
Location: WA, USA
https://jsfiddle.net/v2dvq1ds/3/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 20 posts ]  Go to page Previous  1, 2

All times are UTC - 5 hours


Who is online

Users browsing this forum: Yahoo [Bot] and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group