Advertisement
richarduie

Scalar.html

Mar 2nd, 2019
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.79 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <style>
  6.          #avatar {position:relative;top:120px;left:120px;transform:scale(3);}
  7.     </style>
  8.     <script>
  9.         function Scaler(elementId, minScale, maxScale, deltaScale, direction, deltaMsecs) {
  10.             var scale = (1 == direction)?minScale:maxScale;
  11.             var timer = null;
  12.  
  13.             function incrementScale() {
  14.                 var s = scale + deltaScale*direction;
  15.                 if (s < minScale || s > maxScale) direction *= -1;
  16.                 return scale += deltaScale*direction;
  17.             };
  18.             function doScale(s) {
  19.                 document.getElementById(elementId).style.transform = 'scale(' + s + ')';
  20.             };
  21.  
  22.             this.getDeltaMsecs = function() {return deltaMsecs;};
  23.             this.setTimer = function(t) {timer = t;};
  24.  
  25.             this.run = function() {doScale(incrementScale());};
  26.             this.stop = function() {
  27.                 clearInterval(timer);
  28.                 this.setTimer(null);
  29.             };
  30.         };
  31.  
  32.         var scaler = new Scaler('avatar', 3, 6, .05, 1, 50);
  33.  
  34.         function toggleScaler(ref) {
  35.             if ('run scaler' == ref.value) {
  36.                 ref.value = 'stop scaler';
  37.                 scaler.setTimer(setInterval('scaler.run()', scaler.getDeltaMsecs()));
  38.             }
  39.             else {
  40.                 scaler.stop();
  41.                 ref.value = 'run scaler';
  42.             }
  43.         };
  44.     </script>
  45. </head>
  46. <body>
  47.     <h1>demo the upscaling/downscaling of an image</h>
  48.     <form>
  49.         <input type="button" value="run scaler" onclick="toggleScaler(this);"></input>
  50.     </form>
  51.     <p id="out">
  52.         <img id="avatar" src="https://i.stack.imgur.com/I8wAV.png?s=48&amp;g=1" alt="">
  53.     </p>
  54. </body>
  55. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement