Answer the question
In order to leave comments, you need to log in
How to calculate difference between photo size and jQuery browser screen size?
Greetings friends! Not to say that I am new to JS, but I don't know it well. Now there is a task to find out the size of the picture and the size of the browser window (read the size of the div, because the picture should be located in full screen, and the side that does not fit should go back and forth). I implemented such a solution (the code was cut, the full version of the code can be viewed here ):
var widthImage = $(this).width();
var heightImage = $(this).height();
var doc_w, doc_h;
$(".backgroundImage").css("width", "100%");
doc_h = $(document).width();
var difference = heightImage - doc_h;//Получаем остаток не вошедший в экран в пикселях
if (difference > 1)
{
for (var i = difference; i > 1; i -= 1)
{
$(".testClass").text("Width: " + widthImage + " height: " + heightImage + " screenWidth " + doc_w + " screenHeight " + doc_h + " difference: " + difference);
$("#scene").animate({top: '-=1px'}, 1);
}
}
Answer the question
In order to leave comments, you need to log in
Sketch: jsfiddle.net/0hwrb4he . We still need to refine the updatePrimaryDirection function so that it works correctly with vertically oriented images; check how it works in IE9; handle the situation when the proportions of the container and the image are almost equal and the animation becomes very jerky, and similar trifles.
Write down the percentages, an example of how it changes, instead of a picture of ifrem. www.dulsky.eu/v
$(document).ready(function()
{ $('#player').height($('#player').width()/1.7589879); $(window).resize(function(){
$('#player').height($('#player').width()/1.7589879);}); var bodyHeight = $('body').height(); var vwptHeight = $(window).height();
if (vwptHeight > bodyHeight){$('#player').css({'bottom':'16%'});} ;{$('#t').css({'bottom':'40%'} );} ;{$('#ms').css({'bottom':'2%'} );};{$('#draggable66').css({'bottom':'1%'} );}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question