Re: Performing Double Click and Drag & Drop using Javascript

Wednesday, November 7, 2012

Below is a complete cross-browser compliant page that demonstrates the proper use of setTimeout method.
It simulates the double click functionality via an onclick event attached to a BUTTON
element. Click once on the button and the
psuedoOnClick()function is executed.
Click twice within a 200 millisecond window and psuedoOnDoubleClick() function is executed.

===== BEGIN HTML PAGE
<html>
<head>
<title>setTimeout & Double Click Demo</title>
<script>
// This page implements psuedo double click event via an element's onclick event.

var DBLTIME = 200; // Number of millisecs to wait after first onclick before firing
                   // psuedoOnClick()
                   // If second click happens before this time,
                   // psuedoOnDoubleClick() is called.
var Undef;

function Gid(id) {
    return document.getElementById(id);
}

function Put(id,s) {
    Gid(id).innerHTML = s;
}

var ClickState;    // State variable used to count clicks.

function psuedoOnClick() {
    Put("SH", "You single clicked.");
}

function psuedoOnDoubleClick() {
    Put("SH", "You double clicked.");
}

// This function is called DBLTIME millisconds after
// OnClick() is executed.

function OnTimer() {
    if (ClickState == 1)
        psuedoOnClick();
    ClickState = Undef;
}

function OnClick() {
    if (ClickState == Undef) {
        // The following line will call the OnTimer() function
        // after DBLTIME milliseconds expire.
        window.setTimeout("OnTimer()", DBLTIME);
        ClickState = 1;
        return;
    }
    if (ClickState == 1)
        psuedoOnDoubleClick();
    ClickState = 2;   
}

</script>
</head>
<body>
<button onclick='OnClick()'>Click Me</button>
<div id='SH'></div>
</body>
</html>
====== END HTML PAGE

On Sunday, November 4, 2012 11:40:30 PM UTC-5, Nathan Mynarcik wrote:
This should get ya started: http://www.w3schools.com/jsref/met_win_settimeout.asp



On Sun, Nov 4, 2012 at 9:31 PM, SACHIN V <mr.vs...@gmail.com> wrote:
Hi Nathan,

I don't know how to use it.. Can you please be more elaborate?



--
 
 

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Copyright © 2010 Web Design | Free Blogger Templates by Splashy Templates | Layout by Atomic Website Templates

Vida de bombeiro Recipes Informatica Humor Jokes Mensagens Curiosity Saude Video Games Animals Diario das Mensagens Eletronica Rei Jesus News Noticias da TV Artesanato Esportes Noticias Atuais Games Pets Career Religion Recreation Business Education Autos Academics Style Television Programming Motosport Humor News The Games Home Downs World News Internet Design Entertaimment Celebrities 1001 Games Doctor Pets Net Downs World Enter Jesus Mensagensr Android Rub Letras Dialogue cosmetics Genexus lasofia thebushrajr wingshock tripedes gorduravegetal dainfamia dejavu-transpersonal jsbenfica republicadasbadanas ruiherbon iranianforaryans eaystcheyl fotosdanadir Só Humor Curiosity Gifs Medical Female American Health Madeira Designer PPS Divertidas Estate Travel Estate Writing Computer Matilde Ocultos Matilde futebolcomnoticias girassol lettheworldturn topdigitalnet Bem amado enjohnny produceideas foodasticos cronicasdoimaginario downloadsdegraca compactandoletras newcuriosidades blogdoarmario arrozinhoii