Solution: Image Viewer App using HTML, CSS & JavaScript with source code, demo, and also how you can execute full program easily. To complete the program you need to follow those steps given bellow
Live Demo
Also Helpful –
Age Calculator using JavaScript
Image Viewer App using HTML, CSS & JavaScript
Description
Back to coding, To complete this program with debugging free code you have to create three files. The first file is to HTML and the second file gonna be CSS for design part and the third file JavaScript for function-related,
index.html
Create an HTML file named ‘index.html‘ and put those codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
<!-- Coding Debugging (https://codingdebugging.com) --> <!DOCTYPE html> <html> <head> <title>Image Viewer App - Coding Debugging</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Font Awesome Icon --> <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css"> <!-- Google Font --> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Baloo+Thambi+2:wght@400;500;600;700;800&display=swap"> <!-- My Stylesheet --> <link rel="stylesheet" href="style.css"> </head> <body> <div class="main-box fc wrapper"> <div id="a" class="page fc static"> <div class="center"> <div class="box"> <input id="inp" placeholder="Enter image link"> <button id="btn" onclick="addbro()">View</button> </div> </div> </div> <div id="b" class="page fc"> <div class="clear"> <div id="circle"></div> <img alt="Image Not Found!" src="" id="img"> </div> <div class="https" id="htm"> <p>Click on Screen to Go Back!</p> </div> </div> </div> <!-- Internal JavaScript --> <script src="function.js" type="text/javascript"></script> <script type="text/javascript"> let img = document.getElementById("img"); img.onload = function(){ document.getElementById("circle").style.display = "none"; } img.onunload = function(){ document.getElementById("circle").style.display = "block"; } img.onerror = function(){ document.getElementById("circle").style.display = "none"; } </script> </body> </html> |
style.css
Create a CSS file named ‘style.css‘ and put those codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
*{ margin:0px; padding:0; box-sizing:border-box; } body{ background:#f5f5f5; } .main-box{ background:#333652; } #add{ height:50px; width:50px; background:transparent ; color:#fff; border-radius:50%; text-align:center ; line-height:50px; position:absolute ; right:5px; top:12.5px; box-shadow:0 0 10px 5px rgb(0,0,0,0.05); animation:change 1.5s linear infinite; } .fc { display: flex ; align-items: center ; justify-content: center ; } .wrapper { position: absolute ; top : 0 ; left: 0 ; width : 100vw ; height: 100vh ; overflow: hidden ; perspective: 1000px ; } .page { position: absolute ; width : 100vw ; height: 100vh ; font-size: 20px ; color: #ffffff ; pointer-events: none ; cursor: pointer ; opacity: 0 ; } #b { background: #515bd4; padding:10px; } #a { background-color: #ff6078 ; } #a,#b{ box-shadow:0 0 20px 5px rgb(255,255,255,.05); } .static { opacity: 1 ; pointer-events: all ; } .box{ background:#fff; padding:15px; border-radius:30px; box-shadow:0 0 10px 5px rgb(0,0,0,.05); } #inp{ background:#fff; border:none; font-style:22px; outline:none; padding-left:10px; } #btn{ background:#ff6078; border:1px solid #ff6078; outline:none; color:#fff; padding:5px; width:60px; border-radius:15px; box-shadow:0 0 5px 2.5px rgb(0,0,0,.05); } @keyframes zoom-slide-in { 0% { opacity: 1; transform: scale(0.75) translate(150vw); } 30%{ transform: scale(0.75) translate(150vw); } 75%{ transform: scale(0.75) translate(0vw); } 100%{ opacity: 1; pointer-events: all ; transform: scale(1) translate(0vw); } } @keyframes zoom-slide-out { 0%{ opacity: 100% ; pointer-events: all ; transform: scale(1) translate(0); } 25%{ transform: scale(0.75) translate(0); } 30%{ transform: scale(0.75) translate(0); } 75%{ transform: scale(0.75) translate(-150vw); } 99.99%{ opacity: 100% ; } 100% { pointer-events: none ; opacity: 0 ; transform: scale(0.75) translate(-150vw); } } #img{ max-height:calc(100vh - 20px); outline:none; max-width:calc(100% - 20px); border-radius:10px; box-shadow:0 0 10px 5px rgb(0,0,0,.05); display:none; margin:10px; font-family: "Baloo Thambi 2", cursive; } #circle{ height:50px; width:50px; background:transparent ; border:5px solid #fff; border-color:#fff transparent transparent transparent ; border-radius:50%; animation:rotate 1s linear infinite; display:block ; } .https{ position:absolute ; bottom:15px; font-family: "Baloo Thambi 2", cursive; } @keyframes rotate{ from{ transform:rotate(0deg); } to{ transform:rotate(360deg); } } @keyframes change { 0%{ transform:scale(0.85); } 25%{ transform:scale(1.1); } 50%{ transform:scale(0.85); } 75%{ transform:scale(1); } 100%{ transform:scale(0.85); } } |
function.js
Create a JavaScript file named ‘function.js‘ and put those codes given below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
function addbro(){ let a = document.getElementById("a"); let b = document.getElementById("b"); b.style.animation = "zoom-slide-in 1s ease-in-out forwards"; a.style.animation = "zoom-slide-out 1s ease-in-out forwards"; let input = document.getElementById("inp"); let img = document.getElementById("img"); let htt = document.getElementById("htm"); if(input.value != ""){ img.src = input.value ; img.style.display = "block"; input.value = ""; img.alt = "Wrong Image Link 😒" } else{ img.alt = "Please Enter Image Link 😫"; img.style.display = "block"; } b.onclick = function(){ a.style.animation = "zoom-slide-in 1s ease-in-out forwards"; b.style.animation = "zoom-slide-out 1s ease-in-out forwards"; } htt.style.opacity = 0 ; htt.style.transition = "12s"; } |
Thank you for visiting!
We appreciate you for your precious time. I hope you are learn something from here! If you have any queries about this coding comment down below we will reply ASAP.
Keep coding, Keep debugging!