Code TIPS Link này có tôi ưu hóa ko?

1 bài đăng
09.04.2016 / 09:30
mad
Bài đăng: 2434
Member
Nhào vô cắn tao đi, tao sợ mày à cắn bừa.
JAVASCRIPT
  1. $(function(){
  2. childElement={};
  3. numElement=0;
  4. $('a').hover(function(){
  5. numElement++;
  6. childElement[numElement]=$(this);
  7. //add Element HTML
  8. ref=$(this).attr('href');
  9. name=$(this).text();
  10. tops=$(this).offset().top;
  11. left=$(this).offset().left;
  12. width=$(this).outerWidth();
  13. height=$(this).outerHeight()+5;
  14. if(ref){
  15. ref=ref;
  16. }else{
  17. ref='Không xác định';
  18. }
  19. if(width<=120){
  20. classes='small';
  21. }else{
  22. classes='big';
  23. }
  24. $('body').append('<div class="over_num_'+numElement+' tips_by_mad '+classes+'" style="top: '+tops+'px; left: '+left+'px; margin-top: '+height+'px;">'+name+'<br>'+ref+'</div>');
  25. if(childElement[numElement]){
  26. childElement[numElement].mouseleave(function(){
  27. $('div[class*="over_num_"]').remove();
  28. childElement[numElement]='';
  29. });
  30. }
  31. });
  32.  
  33. })

CSS
  1. .tips_by_mad{
  2. max-width: 200px;
  3. padding: 8px;
  4. color: #ffffff;
  5. text-decoration: none;
  6. background-color: #000000;
  7. -webkit-border-radius: 4px;
  8. -moz-border-radius: 4px;
  9. border-radius: 4px;
  10. position: absolute;
  11. z-index: 1000;
  12. }
  13. .tips_by_mad.big:before{
  14. width: 0;
  15. height: 0;
  16. border: 6px solid transparent;
  17. content: '';
  18. top: -10px;
  19. left: 50%;
  20. margin-left: -5px;
  21. border-bottom-color: #000000;
  22. border-width: 5px;
  23. position: absolute;
  24. border-style: solid;
  25. }
  26. .tips_by_mad.small:before{
  27. width: 0;
  28. height: 0;
  29. border: 6px solid transparent;
  30. content: '';
  31. top: -10px;
  32. left: 10px;
  33. margin-left: -5px;
  34. border-bottom-color: #000000;
  35. border-width: 5px;
  36. position: absolute;
  37. border-style: solid;
  38. }

Nếu code này có sai hay chỗ nào không phù hợp sừa giúp nhé