3. VTU WEB TECHNOLOGY LAB | READ NOW

 VTU WEB TECHNOLOGY LAB

3] WRITE A JAVASCRIPT CODE THAT DISPLAYS TEXT “TEXT-GROWING” WITH INCREASING FONT SIZE IN THE INTERVAL OF 100MS IN RED COLOR, WHEN THE FONT SIZE REACHES 50PT IT DISPLAYS “TEXT-SHRINKING” IN BLUE COLOR. THEN THE FONT SIZE DECREASES TO 5PT


STEPS TO EXECUTE HTML PROGRAM

  1. Copy the html code given below
  2. Save it with .html file name extension
  3. Click double click on your saved html file
  4. Exection successfull

Solution 1 – [prog3.html]

<!DOCTYPE html>
<html>
<body>
 <div id="h"></div>
 <script>
  var v = 0, f = 1,t="TEXT-GROWING",color;
  function a()
  {
   if(f==1)
    v+=5,color="red";
   else
    v-=5,color="blue";
   document.getElementById("h").innerHTML = "<h1 style=\"font-size: "+v+"px ; margin: 0px; color : "+color+"\"><b> "+t+"</b></h1>";
   if(v==50)
    f = 0, t="TEXT-SHRINKING";
   if(v==5)
    f = 1, t="TEXT-GROWING";
   c();
  }
  function c()
  {
   setTimeout(a,300);
  }
  c();
 </script>
</body>
</html>

WEB TECHNOLOGY – Output


WEB TECHNOLOGY Solution 2 – [prog3.html]

<!DOCTYPE HTML>
<html>
<head>
<style>
p {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
</style>
</head>
<body>
<p id="demo"></p>
<script>
var var1 = setInterval(inTimer, 1000);
var fs = 5;
var ids = document.getElementById("demo");
function inTimer() {
ids.innerHTML = 'TEXT GROWING';
ids.setAttribute('style', "font-size: " + fs + "px; color: red");
fs += 5;
if(fs >= 50 ){
clearInterval(var1);
var2 = setInterval(deTimer, 1000);
}

}
function deTimer() {
fs -= 5;
ids.innerHTML = 'TEXT SHRINKING';
ids.setAttribute('style', "font-size: " + fs + "px;
color: blue"); if(fs === 5 ){
clearInterval(var2);
}
}
</script>
</body>

</html>

Leave a Reply

Your email address will not be published. Required fields are marked *

WhatsApp Icon Join For Job Alerts