A
A
abusabir2015-02-04 17:42:59
JavaScript
abusabir, 2015-02-04 17:42:59

JS Pixel size on mobile?

Hello! The question is this:
using JQuery, I scroll to a certain element in this way, for example:

var position = $('#element').offset().top;
$('.btn').click(function(){
   	$('html, body').animate({ scrollTop: position}, 500);	
 }


The bottom line is that on some devices it scrolls normally, but on others (like the iphone 6 for example) it scrolls just a little. Moreover, the position value itself differs by an order of magnitude. I tried to multiply by 2.5 for example (I picked it up empirically) - it works, but accordingly it goes too far on other devices.
I understand that it's all about the size of the real pixel? How is it decided?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SagePtr, 2015-02-04
@SagePtr

window.devicePixelRatio try

P
profesor08, 2015-02-04
@profesor08

Try the plugin to scroll - https://github.com/flesler/jquery.scrollTo
And try instead of 'html, body' - document

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question