Advertisement
Guest User

ese

a guest
Aug 5th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2.  
  3. <head>
  4. <style type="text/css">
  5.     span {
  6.         padding: 5px;
  7.         display: inline-block;
  8.     }
  9.     .hi-light {
  10.         background-color: yellow;
  11.     }
  12. </style>
  13. <script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
  14. <script type="text/javascript">
  15. jQuery(function(){
  16.  
  17. var numberToDisplay = 1000;
  18. var arr = Array.apply(0,new Array(numberToDisplay)).map(function(_,i){ return i+1 });
  19. arr = arr.sort(function(a,b){return Math.random()>0.5});
  20.  
  21. function getFactors(integer){
  22.   var factors = [],
  23.   quotient = 0;
  24.  
  25.   for(var i = 0; i < arr.length; i++){
  26.     quotient = integer/arr[i];
  27.  
  28.     if(quotient === Math.floor(quotient) && integer !== arr[i]){
  29.       factors.push(arr[i]);
  30.     }
  31.   }
  32.   return factors;
  33. }
  34.  
  35. $.each(arr, function(i, v){
  36.     var el = $('<span class="el-'+v+'" value="'+v+'" />').html(v);
  37.     $('body').append(el);
  38.     el.on('mouseover',function(){
  39.         $.each(getFactors($(this).attr('value')), function(ii, vv){
  40.             $('span.el-'+vv+'').addClass('hi-light');
  41.         })
  42.     }).on('mouseout', function(){
  43.         $('span').removeClass('hi-light');
  44.     })
  45.  
  46. })
  47.  
  48. })
  49. </script>
  50. </head>
  51.  
  52.  
  53. <body>
  54.  
  55.  
  56. </body>
  57.  
  58. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement