I'm looking for a separate event handler in Ionic 3 for starting and ending a touch on an HTML element on a mobile app.
I found many related and solved questions, but none for Ionic 3, which currently only seems to support "tap, press, pan, swipe, rotate, and pinch" (https://ionicframework.com/docs/components/#gestures).
And none of these seem to provide a "handler" at the start, but only at the end. I see that then they do give the data of the touch duration (deltaTime), but by that point it's no use for my purposes.
For more context, what I want is to clear a related timeout in the exact moment when the screen is first touched on an element, and then see whether or not this touch on the same specific element ends within a certain time (e.g. 250 ms, so that it can be evaluated as a "tap").
For example something like this:
JS:
timeout_1 = setTimeout(function() {
// do something if timeout_1 not cleared by touch start
}, 4000);
touched(event) {
clearTimeout(timeout_1);
touching_x = true
timeout_2 = setTimeout(function() {
touching_x = false
// store event details and do other things if timeout_2 not cleared by touch end
}, 250);
}
touch_ended(event) {
if (touching_x==true) {
clearTimeout(timeout_2);
// store event details and do some other things
}
}
HTML:
<button ion-button type="button" (button_touch_started) = "touched($event)" (button_touch_ended) = "touch_ended($event)">Touch button</button>
High precision (down to ms) would be important especially for the touch start time.
Any advice is appreciated.
Html
Try either div or button
<div style="height:100%;width:100%" (touchstart)="touchstart($event)" (touchend)="touchend($event)">
</div>
<button ion-button large primary (touchstart)="touchstart($event);">touchstart</button>
<button ion-button large primary (touchend)="touchend($event);">touchend</button>
Ts
touchstart(event){
console.log(event);
}
touchend(event){
console.log(event);
}
Related
<button type="button"
style="background-color:skyblue; border-color:blue; color:white"
className="bn49"
onClick = "this.style.visibility= 'hidden'; window.open('https://frankvanasch.com/elementor-158/','_blank')"
>go
</button>
Reaching your objective with HTML and JavaScript might be impossible if you user know what they are doing.
If you want to hide the button for 11 hours, I'd use localStorage or a cookie to store its status, and to choose if you want to show the button.
And invert the logic, like the button must be hidden by default, and shown only if no interaction has been made, or if the last interaction was more than 11 hours ago.
Somthing like this, of course this snippet cannot run here because of SO localStorage restrictions.
$(".bn49").on("click", function(evt) {
let tgt = evt.target;
$(tgt).hide();
localStorage.setItem("bn49", new Date().toISOString());
window.open('https://frankvanasch.com/elementor-158/', '_blank');
});
$(function() {
let btnTime = localStorage.getItem("bn49");
if (btnTime) {
// there is a time stored, we'll check it
let t = new Date();
t.setHours(t.getHours() - 11);
if (new Date(btnTime).getTime() > t.getTime()) {
// 11 hours have passed, show the button
$(".bn49").show();
}
} else {
// there isn't a time stored, show the button
$(".bn49").show();
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button type="button" style="background-color:skyblue; border-color:blue; color:white; visibility: hidden;" className="bn49">go</button>
My website was working fine before I added more code and features.
It may be because of the tags around the code.
I would like to know how to fix the buttons with numbers (the Cool Music button works fine).
My website is here
<script>
function btnClicked()
{
var audio = new Audio('http://a.tumblr.com/tumblr_lkfhhpM4M41qcmhugo1.mp3');
audio.playbackRate = 2.5;
audio.loop = true;
audio.play();
}
function changeImage1()
{
document.getElementById("image").src= "https://media0.giphy.com/media/sIIhZliB2McAo/200.gif";
}
function changeImage2()
{
document.getElementById("image").src= "https://www.clicktorelease.com/code/gif/1.gif";
}
function changeImage3()
{
document.getElementById("image").src= "http://www.kizoa.com/img/e8nZC.gif";
}
function changeImage4()
{
document.getElementById("image").src= "http://www.netanimations.net/flying_pig_by_rutabaga.gif";
}
</script>
<button onclick="btnClicked()">
Cool Music
</button>
<button onclick="changeImage1()">1</button>
<button onclick="changeImage2()">2</button>
<button onclick="changeImage3()">3</button>
<button onclick="changeImage4()">4</button>
This is not exactly an answer. But this could lead you to the answer.
You have document.getElementById("image").src="<some url>"; in your changeImage functions. But you don't have any DOM element with ID as image. Please check your console and you can find the error yourself.
You're trying to access an element called Image, but from looking through your code I can't find an element with the id of Image.
In the console it shows: "Uncaught TypeError: Cannot set property 'src' of null". This means that it couldn't find the DOM element you are referencing.
You are using document.getElementById("image") but looking at your source code, there is no element with the ID image.
I have a paper-dialog inside of another element looking like:
<paper-dialog id="modal" modal>
<h2>Login</h2>
<p>Lorem......</p>
<div class="buttons">
<paper-button dialog-confirm autofocus>Login</paper-button>
</div>
</paper-dialog>
I could declaratively add entry-animation and exit-animation but I'm really trying to do two effects at once like it shows in the docs
I tried using something like:
this.$.modal.animationConfig = {....}; //like the docs
and I set node to this.$.modal, but I'm pretty certain it doesn't read that variable at all because when I check this.$.modal.getAnimationConfig('exit') (or entry) I get nothing.
So where in the lifecycle can I do something like this.
The end goal for me is to apply to intertwined (one of them slightly delayed) animations to my paper-dialog on entry and exit like in (as he loves to be called :p ) "Bob Dod"'s polycast
If you don't know the answer, pointing me in a different direction also helps ;)
Since it seems my comment was helpful, here it is as an answer:
"Are you sure about this? I tried setting the animationConfig as this.$.modal.animationConfig = { ... } in this fiddle and everything worked just fine..."
I use polymer with angular 2 and this is the way I try to add animation:
if (dialog) {
dialog.animationConfig = {
'entry': {
name: 'transform-animation',
node: dialog,
transformFrom: 'translateY(100%)',
transformTo: 'translateY(0)'
},
'exit': {
name: 'transform-animation',
node: dialog,
transformFrom: 'translateY(0)',
transformTo: 'translateY(100%)'
}
};
dialog.open();
}
I have problem with Edge browser. In my web site I have buttons with span tags inside them. In this span tags I bind text and icons. So far I had no problem but on Edge browser it is possible to click on disabled buttons. After investigating problem I found out that, when button contains span tags inside, it is possible to click on button. Here is how it looks on my web site:
<button id="btnRefresh" type="button" class="btn btn-primary" ng-click="refresh()" ng-disabled="performingAction">
<span ng-class="performingAction && action == 'refresh' ? 'fa fa-cog fa-spin' :'fa fa-refresh'"></span>
<span>{{ refresh }}</span>
</button>
Here is example to testing:
<button type="button" disabled="disabled" onclick='alert("test");'>
<span>Click me!</span>
</button>
One option would be to hide buttons instead of disabling, but I prefer to disable them. Please suggest solution to over come this issue.
Just set
pointer-events: none;
for disabled buttons.
Here's CSS to disable all disabled elements everywhere:
*[disabled] {
pointer-events: none !important;
}
pointer-events documentation
This is a bug in Microsoft Edge. Disabled buttons accept clicks if they contain any HTML elements (i.e. if they contain anything else than just text).
Reported multiple times via Microsoft Connect:
Event bubbles from child element into element (by SO user Ryan Joy)
Bootstrap/Jquery disabled buttons generate click events and show tooltips even disabled
The bug was still present in Build 10565 (16 October 2015).
It was fixed in the November update, Build 10586.
A possible (but ugly) workaround is to call some Javascript in onclick for every button, which then checks if the button is disabled and returns false (thus suppressing the click event).
One work around I've come up with using angularjs is inspired by Ben Nadel's blog here
So for example:
angular.module('myModule').directive(
"span",
function spanDirective() {
return ({
link: function (scope, element, attributes) {
element.bind('click', function (e) {
if (e.target.parentNode.parentNode.disabled || e.target.parentNode.disabled) {
e.stopPropagation();
}
})
},
restrict: "E",
});
}
);
Since you're not always going to be using a span element and probably don't want to create a new directive for every element type, a more general workaround would be to decorate the ngClick directive to prevent the event from reaching the real ngClick's internal event handler when the event is fired on a disabled element.
var yourAppModule = angular.module('myApp');
// ...
yourAppModule.config(['$provide', function($provide) {
$provide.decorator('ngClickDirective', ['$delegate', '$window', function($delegate, $window) {
var isEdge = /windows.+edge\//i.test($window.navigator.userAgent);
if (isEdge) {
var directiveConfig = $delegate[0];
var originalCompileFn = directiveConfig.compile;
directiveConfig.compile = function() {
var origLinkFn = originalCompileFn.apply(directiveConfig, arguments);
// Register a click event handler that will execute before the one the original link
// function registers so we can stop the event.
return function linkFn(scope, element) {
element.on('click', function(event) {
if (event.currentTarget && event.currentTarget.disabled) {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();
}
});
return origLinkFn.apply(null, arguments);
};
};
}
return $delegate;
}]);
}]);
I'd like to add a Next button to all (well... all except the last) panes of an accordion navigation device. As you'd expect, when you click the Next button, the current pane collapses and the next one opens.
It's on a Joomla site, and so we're using MooTools.
I'm having trouble getting the action of the click event to work. Any thoughts?
window.addEvent('domready', function() {
var accordion = new Fx.Accordion($$('#accordion h2'),$$('#accordion .content'), {
onActive: function(toggler,element) { toggler.addClass('active');element.addClass('active'); },
onBackground: function(toggler,element) { toggler.removeClass('active');element.removeClass('active'); }
});
$$('.button.next').addEvent('click', function(event){
event.stop();
accordion.display.getNext(); //HELP HERE PLEASE
});
});
Many thanks!!
Dan
Inspect your accordion instance in console.log(accordion) ;) Try accessing previous property of accordion instance. It doesn't documented and may change with future versions of MooTools More, but it is the easiest way to do what you want:
$$('.button.next').addEvent('click', function(event){
event.stop();
accordion.display(accordion.previous + 1);
});
Working fiddle here: http://jsfiddle.net/9859J/