javascript - I want to return false in clicked time is greater than 200 ms -
i developing youtube player. if user long presses on video, option panel appears. want stop it. possible write query if click time greater 200ms, return false? using code not working.
$('video').on('click', function () { if(longpress) { // if detect hold, stop onclick function return false; }; }); $('video').on('mousedown', function () { longpress = false; //longpress false presstimer = window.settimeout(function(){ // code here longpress = true; //if run hold function, longpress true },300) }); $('video').on('mouseup', function () { cleartimeout(presstimer); //clear time on mouseup });
as @maxx said, declare variables first
var longpress = false; var presstimer; $('video').on('click', function() { console.log(longpress) if (longpress) { // if detect hold, stop onclick function return false; }; }); $('video').on('mousedown', function() { longpress = false; //longpress false presstimer = window.settimeout(function() { // code here longpress = true; //if run hold function, longpress true }, 300) }); $('video').on('mouseup', function() { cleartimeout(presstimer); //clear time on mouseup });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <video style="width: 100px; height: 100px; background-color: rgb(239, 239, 239);"></video>
Comments
Post a Comment