?
Solved

jQuery touch to .Open and .Close

Posted on 2013-02-03
8
Medium Priority
?
589 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 1000 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
Tutorial: Introduction to Managing a Linux Server

In this tutorial on systemd, we will explore:
-OS/Distro Adoption
-chkconfig and Other Legacy Commands
-Summary and Key Commands

 
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 1000 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

Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

765 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