Search results

Repeat Button

The Repeat button is a type of Button in that the click event is triggered at regular time interval from the pressed state till the released state.

The following example explains about how to achieve Repeat Button in mouse and touch events.

tagHelper
repeatbutton.cs
<div class='btncontainer'>
    <ejs-button id="button" content="Button"></ejs-button>
</div>
<div class='event' style="height:auto;">
    <table title='Event Trace' style="width:100%">
    <tbody>
    <tr>
        <th>Event Trace</th>
    </tr>
    <tr>
        <td>
            <div class="eventarea" style="height: 250px;overflow: auto">
                <span id="eventlog" style="word-break: normal;"></span>
            </div>
        </td>
    </tr>
    <tr>
        <td>
            <div class="evtbtn" style="padding:20px 0 0 20px">
                <ejs-button id="clear" content="Clear"></ejs-button>
            </div>
        </td>
    </tr>
</tbody>
</table>
</div>

<style>

hr {
   margin: 1px 10px 1px 0px;
   border-top: 1px solid #eee;
}

.btncontainer {
  float: left;
  width: 40%;
}

.event {
  float: right;
  width: 60%;
  border-left: 1px solid #D7D7D7;
}

#eventlog b {
  color: #388e3c;
}

</style>

<script>

document.getElementById("clear").addEventListener('click', function () {
    document.getElementById('eventlog').innerHTML = '';
});
document.getElementById("button").addEventListener('mousedown', function () {
    event.preventDefault();
    timeout = setInterval(clickEventHandler, 200);
});
document.getElementById("button").addEventListener('touchstart', function () {
    event.preventDefault();
    timeout = setInterval(clickEventHandler, 200);
});
document.getElementById("button").addEventListener('mouseup', function () {
    clearInterval(timeout);
});
document.getElementById("button").addEventListener('touchend', function () {
    clearInterval(timeout);
});
document.getElementById("button").addEventListener('click', function () {
    appendSpanElement('Button click event triggered.<hr>');
});

function clickEventHandler(e){
    appendSpanElement('Button click event triggered.<hr>');
}

function appendSpanElement(text){
    var span = document.createElement('span');
    span.innerHTML = text;
    var log = document.getElementById('eventlog');
    log.insertBefore(span, log.firstChild);
}
</script>
public ActionResult RepeatButton()
{
    return View();
}