1
I’m in trouble with scroll-top
. The implemented function should take the input
that I’ve been with focus
is take you to the top with scroll-top
, but works satisfactorily only for the first few clicks at the top of the page, and when I go down giving click it behaves unsatisfactory rather than leading to the top of the page it leads to the bottom of the page. I have observed that sometimes the value of position
is negative, but this is not always.
I tried to make sure I was up space so that the field rolls up. So the problem is not in the scrolling space.
Below follows my code:
var tamanho = screen.height - 108 - 80;
var inputs = $('input').get();
$(inputs).on('focus', function () {
$(".ajusteTeclado").css("height", tamanho + "px");
$(".ajusteTeclado").show();
var pos = $(this).offset(),
position = pos.top - 60;
// positio/q/108569/4995n = ((position < 0)? position * -1 : position);
console.log(position);
$(this).closest('.scrollPosition').scrollTop(position);
});
What could be ?
I need that every time the field had itself in focus it should locate to the top of the page.
Ever tried to use
pos = $(this).position()
instead ofpos = $(this).offset()
?– Wallace Maxters
Yes, you can actually solve it. Just add $(this). Closest('.scrollPosition'). scrollTop(position); instead of position = pos.top - 60; so position = $(this). Closest('.scrollPosition'). scrollTop(position) + pos.top - 60;
– Renan Rodrigues
So you put that in an answer, so we know more easily what you did.
– Wallace Maxters
Yeah, I’m just compiling project to make sure
– Renan Rodrigues
Ok. Thank you for contributing to the content of the site.
– Wallace Maxters