javascript - How to print a div's width-percentage in that particular offset? -
i have div having width of 300px. want run loop through check width px px (offset offset) , print key percentages in exact position of div (that offset's exact position). how can implemented using javascript? if possible, jquery welcome.
for example, if div of 100px; need print 10 on position of 10px inside div, 20 on 20px , on.
thanks.
as understood you need receive exact percentage offset of element pages offset, if here go :
function percent(){ subj = '#nem'; pageh = window.innerheight; pagew = window.innerwidth; subjtop = $(subj).offset().top; subjleft = $(subj).offset().left; t = ( subjtop / pageh ) * 100; l = ( subjleft / pagew ) * 100; $(subj).html( 't:'+t+' %<br> l: '+l+' %' ); } $(document).ready(function(){percent();}) $(window).resize(function(){percent()})
#nem{ position: absolute; top: 124px; left: 69px; width: 200px; height: 200px; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id='nem'></div>
now if need data updated simultaneously can set interval update data time
Comments
Post a Comment