Double Click

[Total: 0    Average: 0/5]

This example shows how to have a double click feature on your site.

Head Code:

<script> 
var myWin=null;
function openIt() { 
  var _page = "http://www.js-examples.com/"; 
  var _name = "Messages"; 
  var _parms = "status=yes,top=100,left=200,width=250,height=1"; 
  myWin = window.open(_page,_name,_parms) 
} 
function closeIt() {
  if (myWin && myWin != null)
     myWin.close();
}
</script> 

Body Code:

<body onclick="openIt()" > 
<div id="StartMenu"> 
This is the stuff inside the start-menu 
</div> 

<script>  
var h = "hidden";  
var v = "visible";  
function showMenu(_v) { window.document.all.StartMenu.style.visibility = _v?v:h; } 
var double_delay = null;
var delay_value = 1000; // 1 second.
var click_count=0;
function clickMade() {
  if (click_count>0) {
    // it is a double click
	clearTimeout(double_delay);
	double_delay=null;
	showMenu(false);
	closeIt();
  } else {
    // it is a single click
	click_count++;
	showMenu(true);
	double_delay = setTimeout("click_count=0",delay_value);
	openIt();
  }
}
</script>  
<a href="javascript:showMenu(true)">Show stuff</a><BR> 
<a href="javascript:showMenu(false)">Hide stuff</a><BR>
<a href="javascript:clickMade()">Single Click to show, Double Click to hide</a><BR>

Times Viewed: 1

Leave a Reply

Your email address will not be published. Required fields are marked *