[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

jQuery touch to .Open and .Close

Posted on 2013-02-03
8
Medium Priority
?
591 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
Independent Software Vendors: 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 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
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 embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
Suggested Courses

650 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