touch move works once

I have a problem with my html page. I want to deactivate touch move in all page except for a div in which I want scrolling. So I add this js code:

document.ontouchmove = function (e) { if (e.target.id !== 'rest_comm') { e.preventDefault(); } };

It does not always work.

I found with Oscar Paz's help that the problem is that the scrolling div has a lot of divs inside. So how can I deactivate touch move in whole page except for the scrolling div and all its included divs.

Answers


I think that your problem is that e.target won't always be your scrolling div. If you've got elements inside it, e.target is the deepest element in the DOM tree you touched (it could be a paragraph, an image ...). What you've got to do is to check whether e.target is inside your scrolling div, or is your scrolling div. Basically:

    document.addEventListener('touchmove', function(e) {
       var node = e.target;
       while (node && node.id != 'comm_list_content') node = node.parentElement;
       if (!node) e.preventDefault();
    }, false);

This way you'll only call preventDefault() if you touch outside your div.


Need Your Help

double click to open file c#

c# file listbox double-click

I have a listbox filled with file paths. Does anyone know how to open the default program for the file when it's double clicked? For example, if one of the items in the listbox says "c:\test.txt"...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.