Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. var div = document.createElement('div');
  2. div.style.overflowY = 'scroll';
  3. div.style.width = '50px';
  4. div.style.height = '50px';
  5. div.style.visibility = 'hidden';
  6. document.body.appendChild(div);
  7. var scrollWidth = div.offsetWidth - div.clientWidth;
  8. document.body.removeChild(div);
  9. alert( scrollWidth );
  10.  
  11. var div = $("<div>").css({
  12. "overflowY": "scroll",
  13. "width": "50px",
  14. "height": "50px",
  15. "visibility": "hidden"
  16. }).appendTo("body");
  17. var scrollWidth = div.offsetWidth - div.width(); //NaN, т.к нет offsetWidth
  18. div.remove();
  19. alert(scrollWidth);
  20.  
  21. function scrollbarWidth() {
  22. var block = $('<div>').css({'height':'50px','width':'50px'}),
  23. indicator = $('<div>').css({'height':'200px'});
  24.  
  25. $('body').append(block.append(indicator));
  26. var w1 = $('div', block).innerWidth();
  27. block.css('overflow-y', 'scroll');
  28. var w2 = $('div', block).innerWidth();
  29. $(block).remove();
  30. return (w1 - w2);
  31. }
  32.  
  33. alert(scrollbarWidth());
  34.  
  35. function scrollbarWidth() {
  36. var documentWidth = parseInt(document.documentElement.clientWidth);
  37. var windowsWidth = parseInt(window.innerWidth);
  38. var scrollbarWidth = windowsWidth - documentWidth;
  39. return scrollbarWidth;
  40. }
  41.  
  42. @media only screen and (max-width: 1024px)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement