I can’t get this to work, i think i’m going in the right direction… but can’t get this to work can anyone help me out?? Basically, what I need to do is get this picture to resize based on what the user clicks. Three different sizes, 50%, 100% and 150% of current size. Am I doing this correctly? Would anyone be able to help me out?
[code=html]
<!doctype html>
<html lang=”en”>
<head>
<title>Change Image Size</title>
<style>
body {width: 80%; margin: auto;}
header {border-bottom: 1px solid #aaa;}
header h1 {font-size: 1.5em;}
nav {float: left; width: 15%; margin: 2% 2%; }
main {float: left; width: 60%; border: 0px black solid; margin: 2% 2%; height: 500px; padding: 1em;}
main img {border: 1px black solid;}
nav span {display: inline-block; width:100px; height: 30px; border: 1px solid black; border-radius: 10px; text-align: center; margin-bottom: 1em; background-color: green; color: white;}
</style>
<script>
function init (){
document.getElementById(‘small’).onclick = function () {change(‘div1’,50,50)};
document.getElementById(‘medium’).onclick = function () {change(‘div1’,100,100)};
document.getElementById(‘large’).onclick = function () {change(‘div1’,150,150)};
}
function change(id, y, x){
var img = document.getElementById(‘div1’);
img.style.width = img.offsetWidth + y + “px”;
img.style.height = img.offsetHeight + x + “px”;
document.getElementById(id).style.width = y;
document.getElementById(id).style.height = x;
}
window.onload = init;
</script>
</head>
<body>
<header><h1>CTEC 4350 DHTML Exercise: Change Image Size</h1></header>
<nav>
<span id=”small”>50%</span>
<span id=”medium”>100%</span>
<span id=”large”>150%</span>
</nav>
<main>
<p> This image is displayed at 150% of its orignal size. (The number of % changes based on the size option picked by the user.)</p>
<p> To complete this exercise, you will need to research on how to get the original size of an image.</p>
<div id=”div1″>
<img src=”http://omega.uta.edu/~cyjang/ctec4350/labex/dhtml/alice28a.gif” height=”400px” width=”400px”>
</div>
</main>
</body>
</html>