{"id":279,"date":"2013-02-11T05:33:00","date_gmt":"2013-02-11T05:33:00","guid":{"rendered":"https:\/\/pim.famnit.upr.si\/wp\/?p=279"},"modified":"2021-11-17T11:18:54","modified_gmt":"2021-11-17T11:18:54","slug":"bootstrap-progress-bar-in-100-images-for-older-browsers","status":"publish","type":"post","link":"https:\/\/pim.famnit.upr.si\/wp\/?p=279","title":{"rendered":"Bootstrap progress bar in 100 images for older browsers"},"content":{"rendered":"<p>These are assumptions taken here:<\/p>\n<ul>\n<li><a href=\"http:\/\/twitter.github.com\/bootstrap\/components.html#progress\">Bootstrap<\/a> progress bars are nice<\/li>\n<li>They do not work in IE 6-9 (I really wonder why 24% of web users don&#8217;t upgrade their browsers):<br \/><em>&quot;Progress bars use CSS3 gradients, transitions, and animations to achieve<br \/>\n all their effects. These features are not supported in IE7-9 or older<br \/>\nversions of Firefox.&quot;<\/em><\/li>\n<li>I needed a progress bar for a web form that would work in all browsers <\/li>\n<li>I&#8217;m calculating how much of a web form is completed with <a href=\"http:\/\/angularjs.org\/\">AngularJS<\/a> and change the progress bar on he fly.<\/li>\n<\/ul>\n<p>Let&#8217;s start.<\/p>\n<p><strong>1. Create 100 progress bars using a php loop and a <a href=\"http:\/\/twitter.github.com\/bootstrap\/components.html#progress\">Bootstrap progress bar code<\/a>:<\/strong><\/p>\n<pre style=\"background-color: #ffffd2;\"> &lt;!doctype html&gt;\r\n &lt;html&gt;\r\n&nbsp;&nbsp;&nbsp; &lt;head&gt;&nbsp;&nbsp;&nbsp; \r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;link rel=\"stylesheet\" href=\"lib\/bootstrap\/css\/bootstrap.min.css\"&gt;\r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;script src=\"lib\/bootstrap\/js\/bootstrap.min.js\"&gt;&lt;\/script&gt;\r\n&nbsp;&nbsp;&nbsp; &lt;\/head&gt;\r\n&nbsp;&nbsp;&nbsp; &lt;body&gt;\r\n\r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;div id=\"progress_bar\" style=\"width: 500px; margin: 10px auto 0 auto\"&gt;\r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;?php\r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; for ($i=0; $i&lt;101; $i++) { \r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; echo '&nbsp; &lt;div class=\"progress\" <span><span class=\"attribute-name\">style<\/span>=\"<a class=\"attribute-value\">margin: 2px<\/a>\"<\/span>&gt;\r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;div class=\"bar\" style=\"width: '.$i.'%\"&gt;&lt;\/div&gt;\r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;\/div&gt;';\r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; ?&gt;\r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &lt;\/div&gt;\r\n&nbsp;&nbsp;&nbsp; &lt;\/body&gt;\r\n &lt;\/html&gt;<\/pre>\n<p>It is possible to use other colours and stripes, etc &#8230; but I&#8217;ll use simplest progress bar. Keep in mind that my outer div is 500px wide as this is the size of a progress bar I wanted.<\/p>\n<p><strong>2. Crop the progress bars from a web page produces by the above code <\/strong><\/p>\n<p>The simplest way is to use <a href=\"http:\/\/awesomescreenshot.com\/\">Awesome screenshot<\/a> extension for Chrome, Safari or Firefox. It is also good to cut down the image size with e.g. re-saving it for the web so it would be smaller in size (not resolution).<\/p>\n<p>I ended up with this image (<a href=\"uploads\/progressbar_small.png\">original size can be downloaded here<\/a>):<\/p>\n<p><a href=\"uploads\/progressbar_small.png\"><img decoding=\"async\" src=\"https:\/\/pim.famnit.upr.si\/wp\/wp-content\/uploads\/2021\/11\/progressbar_small_tn.png\" class=\"no_float\" \/><\/a><\/p>\n<p>This can be already the end of the story. The only thing wee need is to use this image as a background of a div and slide up or down based on the percentage we want to show.<\/p>\n<p><strong>3. Show the progress bar <\/strong><\/p>\n<p><strong>3.1 Using CSS<\/strong> background-position <strong>and AngularJS binding<\/strong> <\/p>\n<pre style=\"background-color: #ffffd2;\"> &lt;div style=\"float: left;\"&gt;Progress: &lt;\/div&gt;\r\n &lt;div style=\"width: 500px; height: 22px; float: left;\r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; background-image:url('progressbar_small.png'); \r\n&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; background-position:0px -{{Math.round(22*(percentage))}}px;\"&gt;\r\n &lt;\/div&gt;<\/pre>\n<p>Each progress bar is 22px high and I multiply it with the percentage I calculate based on how much of the form is filled in. I also use the Math JS in binding for multiplication (maybe there&#8217;s a better way but I&#8217;m not aware of any). To do this I had to define the Math object in my $scope this way $scope.Math = window.Math;&nbsp; <\/p>\n<p>For some reason the above did not work in IE 8 (which I really care about). Although it apparently works on some web sites. So i decided to slice up the above image in 100 images.<\/p>\n<p> <strong>3.2 Using individual images<\/strong><\/p>\n<p>This is not the optimum solution as for every change there is an Ajax get call to retrieve a desired image. We did this only once in the above example.<\/p>\n<p>This procedure was also <a href=\"\/blog\/index.php?\/archives\/298-Slice-up-an-image-in-100-slices-with-ImageMagick-or-a-progress-bar-in-100-images.html\">explained in a previous post<\/a>.<\/p>\n<p>First I sliced up the image with <a href=\"http:\/\/www.imagemagick.org\/Usage\/crop\/#crop\">ImageMagick using a crop flag<\/a> (the second command should be in one line) using a bash one line script:<\/p>\n<pre style=\"background-color: #ffffd2;\"> mk@here\/$ ls\r\n progressbar_small.png\r\n\r\n mk@here\/$ for((i=0; i&lt;101; i++)) ; do n=$[i*22]; \\ \r\n          convert progressbar_small.png -crop 500x22+0+$n +repage progressbar${i}.png; \\\r\n          done\r\n\r\n mk@here\/$ ls\r\n progressbar0.png&nbsp;&nbsp;&nbsp; progressbar32.png&nbsp; progressbar56.png&nbsp; progressbar7.png\r\n ...\r\n progressbar2.png&nbsp;&nbsp;&nbsp; progressbar53.png&nbsp; progressbar77.png&nbsp; progressbar_small.png\r\n<\/pre>\n<p>The -crop flag slices up images 500px wide and 22px high and starts at 0px on the X axis and goes down 22*i where i runs from 0 to 100. The end results are 100 images.<\/p>\n<p>And finally the HTML bit: <\/p>\n<\/p>\n<pre style=\"background-color: #ffffd2;\"> &lt;div style=\"float: left;\"&gt;Progress: &lt;\/div&gt;\r\n &lt;div style=\"width: 500px; height: 22px; float: left;\"&gt;\r\n     &lt;img src=progressbar{{Math.round(22*(percentage))}}.png\"&gt;\r\n &lt;\/div&gt;<\/pre>\n<p>All&nbsp; images are available <a href=\"uploads\/progress_bar.zip\">in this zip file<\/a>.<\/p>\n<p>I hope this can help someone.<\/p>\n<p>Any other suggestions greatly appreciated.<\/p>\n<p>A big thank you to Tine for all the suggestions and help.<\/p>\n<ul> <\/ul>\n","protected":false},"excerpt":{"rendered":"<p>These are assumptions taken here: Bootstrap progress bars are nice They do not work in IE 6-9 (I really wonder why 24% of web users don&#8217;t upgrade their browsers):&quot;Progress bars use CSS3 gradients, transitions, and animations to achieve all their effects. These features are not supported in IE7-9 or older versions of Firefox.&quot; I needed&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-279","post","type-post","status-publish","format-standard","hentry","category-6-pim-research"],"_links":{"self":[{"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/posts\/279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=279"}],"version-history":[{"count":2,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/posts\/279\/revisions"}],"predecessor-version":[{"id":1187,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=\/wp\/v2\/posts\/279\/revisions\/1187"}],"wp:attachment":[{"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pim.famnit.upr.si\/wp\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}