Skip to content

Instantly share code, notes, and snippets.

@motsu0
Created February 11, 2020 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save motsu0/b597064e0a653113cb72bb6742530be7 to your computer and use it in GitHub Desktop.
Save motsu0/b597064e0a653113cb72bb6742530be7 to your computer and use it in GitHub Desktop.
<button id="bt-prac">長押しでアラート</button>
<p id="op-prac">.</p>
<script src="path/to/long-press.js"></script>
const check_sec = 500; //ミリ秒
const target_element = document.getElementById('bt-prac');
const op_prac = document.getElementById('op-prac');
long_press(target_element, normal_func, long_func, check_sec);
function normal_func(){
op_prac.textContent = '通常のクリック or タップ';
}
function long_func(){
op_prac.textContent = '.';
window.alert('長押ししました');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment