Solved

jQuery touch to .Open and .Close

Posted on 2013-02-03
8
587 Views
Last Modified: 2013-03-02
Hi people,

Does anyone know how to replicate the hover function on touch devices?

I am able to open a dropdown menu with touch but I can seem to get it to close when touched!

<script>
<-- Below opens the dropdown -->
jQuery('.dropdown-toggle').on('touchstart', function(e) {		 
	e.stopPropagation();
   var dropdown = jQuery(this).open(".dropdown-menu");

<-- Now I am trying to close on touch --> 
   jQuery('.dropdown-toggle').on('touchstart', function(e) {		 
	e.stopPropagation();
   var dropdown = jQuery(this).removeclass(".open");
   });
});
</script>

Open in new window


Any able to point me in the right direction will be much appreciated...
0
Comment
Question by:rafique12
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38848664
I don't work with mobile, but I have seen things like this:

$("a").live("touchstart", function(e) {
  $(this).trigger("hover");
});


Cd&
0
 
LVL 11

Assisted Solution

by:mcnute
mcnute earned 250 total points
ID: 38850289
In order to make the on function work put an additional dom element in it like in the code block. In order to know that your touchstart is triggered insert some console.log()
 statements, so you definitely know it is triggered at all.

Yet another thing, in the jquery mobile docs I couldn't find such method as open(), what I found was popup( open ) or dialog( open ). You consider using toggleSlide() instead of open.
<script>
<-- Below opens the dropdown -->
jQuery('.dropdown-toggle').on('touchstart', 'li', function(e) {            
      e.stopPropagation();
   var dropdown = jQuery(this).toggleSlide(".dropdown-menu", 400);

<-- Now I am trying to close on touch -->
   jQuery('.dropdown-toggle').on('touchstart', 'li', function(e) {            
        console.log('submenu hiding triggered');
      e.stopPropagation();
        var dropdown = jQuery(this).toggleSlide(".dropdown-menu", 400);
   });
});
</script>
0
 

Author Comment

by:rafique12
ID: 38850527
Thanks for the contributions guys!

But I've not been able to use touch to close using either of the above methods^
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 53

Expert Comment

by:COBOLdinosaur
ID: 38852210
Then maybe you should post a link instead of expecting a solution when all you have given us is a fragment of code with no context.

Cd&
0
 
LVL 6

Expert Comment

by:lightspeedvt
ID: 38882277
Same as JQuery library are you sure that you have jQuery mobile library loaded to the site too (http://jquerymobile.com/)?
0
 

Author Comment

by:rafique12
ID: 38886946
^The link is dead, but yes I have it loaded.

Thanks for the response though!
0
 
LVL 6

Accepted Solution

by:
lightspeedvt earned 250 total points
ID: 38886962
Link is:

http://jquerymobile.com/

If you have it loaded too, in this case it is really needed to see the link, as there could be a lot of things that may break functions working correctly.
0
 

Author Closing Comment

by:rafique12
ID: 38946712
Sorry for not closing this sooner
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question