How do I print a fraction of the width of a div at that particular offset?

I have a div that is 300px wide. I want to run a loop through it that will check its px width by px (offset by offset) and print the percentages at that exact div position (that's the exact position). How can this be implemented using Javascript? JQuery is welcome if possible.

For example, if the div is 100px; then I will need to print 10 at the 10px position inside the div, 20 by 20px, etc.

Thank.

+3


source to share


1 answer


As I understand it , you need to get the EXACT percentage offset of the FROM THE PAGES OFFSET element , if that's how you are here:



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>
      

Run codeHide result


now if you need this data to be updated at the same time, you can set the interval to update the data by time

0


source







All Articles