언어 설정

Menu
Sites
Language
How to disabled image long tap in my application

Hi,

I have developed and application in which i want to disable image long tap.How can i do this.On the long touch of image it should be disabled.

 

please help me.

 

 

Thanks and regards

Mohit Kumar

 

Responses

4 댓글
colin Rao

Hi,

As I know, there isn't long press event on raw html tag. which javascript framework do you use? and please check in your js file is there any long press event register on img tag.

Marco Buettner

if you use jQuery you can use "taphold" event

$('img').on('taphold', function() {
    // DO YOU CODE
});

 

Vikram

Hi,

You can use the jQuery code below

<body>
<script>
$(document).on("pageinit","#pageone",function(){
  $("p").on("taphold",function(){
    $(this).hide();
  });                       
});
</script>

<div data-role="page" id="pageone">
  <div data-role="header">
    <h1>tap hold event</h1>
  </div>

  <div data-role="content">
    <p>tap hide</p>
  </div>
</div> 
</body>

 

pius lee

If you don't like jquery then you can implement long click like it.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
</head>
<body>
<button id="longclick">longclick</button>
<script>

window.onload = function() {
    var btn = document.getElementById("longclick");
	addLongclickEventListener(btn, function(ev) {
		console.log(ev);
	}, false);
	btn.addEventListener("click", function(ev) {console.log("click!");}, false);
}

function addLongclickEventListener(elem, listener, click_time) {
	click_time = click_time || 1000;
	
	elem.addEventListener('longclick', listener, false);

	var timer = null;
	function resetEvent() {
		if (timer !== null) {
			clearTimeout(timer);
			timer = null;
		}
	}
	function fireEvent(ev) {
		var event = new CustomEvent("longclick", {detail:ev, bubbles:false, cancelable:false});
		ev.target.dispatchEvent(event);
	}

	elem.addEventListener('mousedown', function(ev) {
		resetEvent();
		if (timer === null) timer = window.setTimeout(function() {fireEvent(ev);}, click_time);
	}, false);

	elem.addEventListener('mousemove', resetEvent, false);
	elem.addEventListener('mouseup', resetEvent, false);
}
</script>
</body>
</html>