Guest User

Untitled

a guest
Jan 25th, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. -----------------------------------------------------------------first code------------------------------------------------------------
  2. <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  3.  
  4. <script type='text/javascript'>
  5.  
  6. //<![CDATA[
  7.  
  8.  
  9.  
  10. $(document).ready(function(){
  11.  
  12.  
  13.  
  14. var getMax = function(){
  15.  
  16. return $(document).height() - $(window).height();
  17.  
  18. }
  19.  
  20.  
  21.  
  22. var getValue = function(){
  23.  
  24. return $(window).scrollTop();
  25.  
  26. }
  27.  
  28.  
  29.  
  30. if('max' in document.createElement('progress')){
  31.  
  32. // Browser supports progress element
  33.  
  34. var progressBar = $('progress');
  35.  
  36.  
  37.  
  38. // Set the Max attr for the first time
  39.  
  40. progressBar.attr({ max: getMax() });
  41.  
  42.  
  43.  
  44. $(document).on('scroll', function(){
  45.  
  46. // On scroll only Value attr needs to be calculated
  47.  
  48. progressBar.attr({ value: getValue() });
  49.  
  50. });
  51.  
  52.  
  53.  
  54. $(window).resize(function(){
  55.  
  56. // On resize, both Max/Value attr needs to be calculated
  57.  
  58. progressBar.attr({ max: getMax(), value: getValue() });
  59.  
  60. });
  61.  
  62. }
  63.  
  64. else {
  65.  
  66. var progressBar = $('.progress-bar'),
  67.  
  68. max = getMax(),
  69.  
  70. value, width;
  71.  
  72.  
  73.  
  74. var getWidth = function(){
  75.  
  76. // Calculate width in percentage
  77.  
  78. value = getValue();
  79.  
  80. width = (value/max) * 100;
  81.  
  82. width = width + '%';
  83.  
  84. return width;
  85.  
  86. }
  87.  
  88.  
  89.  
  90. var setWidth = function(){
  91.  
  92. progressBar.css({ width: getWidth() });
  93.  
  94. }
  95.  
  96.  
  97.  
  98. $(document).on('scroll', setWidth);
  99.  
  100. $(window).on('resize', function(){
  101.  
  102. // Need to reset the Max attr
  103.  
  104. max = getMax();
  105.  
  106. setWidth();
  107.  
  108. });
  109.  
  110. }
  111.  
  112. });
  113.  
  114. $(document).ready(function(){
  115.  
  116.  
  117.  
  118. $('#flat').addClass("active");
  119.  
  120. $('#progressBar').addClass('flat');
  121.  
  122.  
  123.  
  124. $('#flat').on('click', function(){
  125.  
  126. $('#progressBar').removeClass().addClass('flat');
  127.  
  128. $('a').removeClass();
  129.  
  130. $(this).addClass('active');
  131.  
  132. $(this).preventDefault();
  133.  
  134. });
  135.  
  136.  
  137.  
  138. });
  139.  
  140. //]]>
  141.  
  142. </script>
  143.  
  144.  
  145. --------------------------------------------------------------second code--------------------------------------------------------------
  146.  
  147. <progress id='progressBar' value='0'>
  148.  
  149. <div class='progress-container'>
  150.  
  151. <span class='progress-bar'/>
  152.  
  153. </div>
  154.  
  155. </progress>
  156.  
  157.  
  158. ---------------------------------------------------------------final code--------------------------------------------------------------
  159.  
  160.  
  161. /* reading position indicator */
  162.  
  163.  
  164.  
  165. progress {
  166.  
  167.  
  168.  
  169. /* Positioning */
  170.  
  171.  
  172.  
  173. position: fixed;
  174.  
  175.  
  176.  
  177. left: 0;
  178.  
  179.  
  180.  
  181. bottom: 0;
  182.  
  183.  
  184.  
  185. z-index: 101;
  186.  
  187.  
  188.  
  189. /* Dimensions */
  190.  
  191.  
  192.  
  193. width: 100%;
  194.  
  195.  
  196.  
  197. height: .25em;
  198.  
  199.  
  200.  
  201. /* Reset the apperance */
  202.  
  203.  
  204.  
  205. -webkit-appearance: none;
  206.  
  207.  
  208.  
  209. -moz-appearance: none;
  210.  
  211.  
  212.  
  213. appearance: none;
  214.  
  215.  
  216.  
  217. /* Get rid of the default border in Firefox/Opera. */
  218.  
  219.  
  220.  
  221. border: none;
  222.  
  223.  
  224.  
  225. /* For Firefox/IE10+ */
  226.  
  227.  
  228.  
  229. background-color: transparent;
  230.  
  231.  
  232.  
  233. /* For IE10+, color of the progress bar */
  234.  
  235.  
  236.  
  237. color: red;
  238.  
  239.  
  240.  
  241. }
  242.  
  243.  
  244.  
  245.  
  246.  
  247. progress::-webkit-progress-bar {
  248.  
  249.  
  250.  
  251. background-color: transparent;
  252.  
  253.  
  254.  
  255. }
  256.  
  257.  
  258.  
  259. .flat::-webkit-progress-value {
  260.  
  261.  
  262.  
  263. background-color: red;
  264.  
  265.  
  266.  
  267. }
  268.  
  269.  
  270.  
  271. .flat::-moz-progress-bar {
  272.  
  273.  
  274.  
  275. background-color: red;
  276.  
  277.  
  278.  
  279. }
  280.  
  281.  
  282.  
  283. .progress-container {
  284.  
  285.  
  286.  
  287. width: 100%;
  288.  
  289.  
  290.  
  291. background-color: transparent;
  292.  
  293.  
  294.  
  295. position: fixed;
  296.  
  297.  
  298.  
  299. top: 0;
  300.  
  301.  
  302.  
  303. left: 0;
  304.  
  305.  
  306.  
  307. height: .25em;
  308.  
  309.  
  310.  
  311. display: block;
  312.  
  313.  
  314.  
  315. }
  316.  
  317.  
  318.  
  319. .progress-bar {
  320.  
  321.  
  322.  
  323. background-color: red;
  324.  
  325.  
  326.  
  327. width: 50%;
  328.  
  329.  
  330.  
  331. display: block;
  332.  
  333.  
  334.  
  335. height: inherit;
  336.  
  337. }
Advertisement
Add Comment
Please, Sign In to add comment