/    Sign up×
Community /Pin to ProfileBookmark

zooming image in all direction

I’m developing the following code for zooming and draggin’ that works through
different web browsers such as opera FF IE and so on what I want is to customize my code to make zooming image in all direction: y-up,y-down,x-left,x-right all simultaneously. exactly like the folloing link
[url]http://jibbering.com/routeplanner/#[/url]

here is my code to be customized:

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd“>
<html lang=”en”>
<head>
<title>Dynamically Scaling Image Maps</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″>
<meta http-equiv=”imagetoolbar” content=”no”>

<style type=”text/css”>
.dragclass{
position : relative;
cursor : move;
}
</style>

<script type=”text/javascript”>

if (document.getElementById){

(function(){

if (window.opera){
document.write(“<input type=’hidden’ id=’Q’ value=’ ‘>”);
}

var n = 500;
var dragok = false;
var y,x,d,dy,dx;

function move(e){
if (!e) e = window.event;
if (dragok){
d.style.left = dx + e.clientX – x + “px”;
d.style.top = dy + e.clientY – y + “px”;
return false;
}
}

function down(e){
if (!e) e = window.event;
var temp = (typeof e.target != “undefined”)?e.target:e.srcElement;
if (temp.tagName != “HTML”|”BODY” && temp.className != “dragclass”){
temp = (typeof temp.parentNode != “undefined”)?temp.parentNode:temp.parentElement;
}
if (temp.className == “dragclass”){
if (window.opera){
document.getElementById(“Q”).focus();
}
dragok = true;
temp.style.zIndex = n++;
d = temp;
dx = parseInt(temp.style.left+0);
dy = parseInt(temp.style.top+0);
x = e.clientX;
y = e.clientY;
document.onmousemove = move;
return false;
}
}

function up(){
dragok = false;
document.onmousemove = null;
}

document.onmousedown = down;
document.onmouseup = up;

})();
}//End.
</script>

<script type=”text/javascript”>

function getMap(elImage) {
// Be sure a map is specified for the image.
if (null != elImage.getAttribute(‘usemap’)) {
// Remove the leading # from the bookmark.
var strMap = elImage.getAttribute(‘usemap’).substring(1);
// Return the element with the specified name.
return strMap;
}
return null;
}

function zoomImage(elImage, amount) {

// Expand the image the specified amount.
var elMap = getMap(elImage);

elImage.width *= amount;
elImage.height *= amount;
// If an image map is available, scale it too.
if (null != elMap) {
elMap=document.getElementsByName(elMap)[0];
for (var intLoop = 0; intLoop < elMap.areas.length; intLoop++) {
var elArea = elMap.areas[intLoop];
// Break the coordinates string into an array.
var coords = elArea.coords.split(“,”);
var scaledCoords = “”;
// Rebuild the new scaled string.
for (coord in coords) {
scaledCoords += (coords[coord] * amount) + “,”;
}

// Put the scaled coordinates back into the map.
elArea.coords = scaledCoords;
}
}
}

</script>

</head><BODY >

<DIV ID=”myDiv”
style=”margin-bottom: 600px;margin-top: 80px; margin-left: 300px; margin-right: 200px; text-align: center;BORDER-RIGHT: #ffffff 1px; BORDER-TOP: #ffffff 1px; Z-INDEX: 1; VISIBILITY: visible; overflow:hidden; BORDER-LEFT: #ffffff 1px; WIDTH: 200px; BORDER-BOTTOM: #ffffff 1px; POSITION:absolute; top:10px;right:50px; HEIGHT: 200px; BACKGROUND-COLOR: #ffffff; layer-background-color: #FFFFFF ; padding:0″ >

<IMG src=”places.gif” id=”img1″ class=”dragclass” onmousemove=”showPosition(event)” name=imageName usemap=”#map1″ width=”200″ height=”200″ border=”0″ >

</div>

<p>
<input value=”Zoom In” onclick=”zoomImage(document.getElementById(‘img1’), 2); ” id=”zoomin” type=”button”>
<input value=”Zoom Out” onclick=”zoomImage(document.getElementById(‘img1’), .5); ” id=”zoomout” type=”button”>
</p>
<p>

</body>
</html>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsNov 11.2008 — [CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Dynamically Scaling Image Maps</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="imagetoolbar" content="no">




<style type="text/css">
.dragclass{
position : relative;
cursor : move;
}
</style>


<script type="text/javascript">


if (document.getElementById){

(function(){


if (window.opera){
document.write("<input type='hidden' id='Q' value=' '>");
}

var n = 500;
var dragok = false;
var y,x,d,dy,dx;

function move(e){
if (!e) e = window.event;
if (dragok){
var lft=dx + e.clientX - x;
var top=dy + e.clientY - y;
d.style.left = Math.min(Math.max(-d.width+d.parentNode.offsetWidth,lft),0) + "px";
d.style.top = Math.min(Math.max(-d.height+d.parentNode.offsetHeight,top),0) + "px";
return false;
}
}

function down(e){
if (!e) e = window.event;
var temp = (typeof e.target != "undefined")?e.target:e.srcElement;
if (temp.tagName != "HTML"|"BODY" && temp.className != "dragclass"){
temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
}
if (temp.className == "dragclass"){
if (window.opera){
document.getElementById("Q").focus();
}
dragok = true;
temp.style.zIndex = n++;
d = temp;
dx = parseInt(temp.style.left+0);
dy = parseInt(temp.style.top+0);
x = e.clientX;
y = e.clientY;
document.onmousemove = move;
return false;
}
}

function up(){
dragok = false;
document.onmousemove = null;
}

document.onmousedown = down;
document.onmouseup = up;

})();
}//End.
</script>





<script type="text/javascript">






function getMap(elImage) {
// Be sure a map is specified for the image.
if (null != elImage.getAttribute('usemap')) {
// Remove the leading # from the bookmark.
var strMap = elImage.getAttribute('usemap').substring(1);
// Return the element with the specified name.
return strMap;
}
return null;
}

function zoomImage(elImage, amount) {
// Expand the image the specified amount.
var elMap = getMap(elImage);
var zxcoldx=(elImage.width-elImage.parentNode.offsetWidth)/2;
var zxcoldy=(elImage.height-elImage.parentNode.offsetHeight)/2;
var zxcp=elImage.parentNode;
if (elImage.width * amount<zxcp.offsetWidth||elImage.height * amount<zxcp.offsetHeight) return;
elImage.width *= amount;
elImage.height *= amount;
elImage.style.left=parseInt(elImage.style.left)-(elImage.width-zxcp.offsetWidth)/2+zxcoldx+'px';
elImage.style.top=parseInt(elImage.style.top)-(elImage.height-zxcp.offsetHeight)/2+zxcoldx+'px';
// If an image map is available, scale it too.
if (null != elMap) {
elMap=document.getElementsByName(elMap)[0];
for (var intLoop = 0; intLoop < elMap.areas.length; intLoop++) {
var elArea = elMap.areas[intLoop];
// Break the coordinates string into an array.
var coords = elArea.coords.split(",");
var scaledCoords = "";
// Rebuild the new scaled string.
for (coord in coords) {
scaledCoords += (coords[coord] * amount) + ",";
}

// Put the scaled coordinates back into the map.
elArea.coords = scaledCoords;
}
}
}



</script>









</head>

<BODY onload="">




<DIV ID="myDiv"
style="margin-bottom: 600px;margin-top: 80px; margin-left: 300px; margin-right: 200px; text-align: center;BORDER-RIGHT: #ffffff 1px; BORDER-TOP: #ffffff 1px; Z-INDEX: 1; VISIBILITY: visible; overflow:hidden; BORDER-LEFT: #ffffff 1px; WIDTH: 200px; BORDER-BOTTOM: #ffffff 1px; POSITION:absolute; top:10px;right:50px; HEIGHT: 200px; BACKGROUND-COLOR: #ffffff; layer-background-color: #FFFFFF ; padding:0" >

<IMG src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" id="img1" class="dragclass" style="position:relative;left:0px;top:0px;" name=imageName usemap="#map1" width="200" height="200" border="0" >

</div>

<map name="map1" ></map>

<p>
<input value="Zoom In" onclick="zoomImage(document.getElementById('img1'), 2); " id="zoomin" type="button">
<input value="Zoom Out" onclick="zoomImage(document.getElementById('img1'), .5); " id="zoomout" type="button">
</p>
<p>


</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@vwphillipsNov 11.2008 — [CODE]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<title>Dynamically Scaling Image Maps</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="imagetoolbar" content="no">




<style type="text/css">
.dragclass{
position : relative;
cursor : move;
}
</style>


<script type="text/javascript">


if (document.getElementById){

(function(){


if (window.opera){
document.write("<input type='hidden' id='Q' value=' '>");
}

var n = 500;
var dragok = false;
var y,x,d,dy,dx;

function move(e){
if (!e) e = window.event;
if (dragok){
var lft=dx + e.clientX - x;
var top=dy + e.clientY - y;
d.style.left = Math.min(Math.max(-d.width+d.parentNode.offsetWidth,lft),0) + "px";
d.style.top = Math.min(Math.max(-d.height+d.parentNode.offsetHeight,top),0) + "px";
return false;
}
}

function down(e){
if (!e) e = window.event;
var temp = (typeof e.target != "undefined")?e.target:e.srcElement;
if (temp.tagName != "HTML"|"BODY" && temp.className != "dragclass"){
temp = (typeof temp.parentNode != "undefined")?temp.parentNode:temp.parentElement;
}
if (temp.className == "dragclass"){
if (window.opera){
document.getElementById("Q").focus();
}
dragok = true;
temp.style.zIndex = n++;
d = temp;
dx = parseInt(temp.style.left+0);
dy = parseInt(temp.style.top+0);
x = e.clientX;
y = e.clientY;
document.onmousemove = move;
return false;
}
}

function up(){
dragok = false;
document.onmousemove = null;
}

document.onmousedown = down;
document.onmouseup = up;

})();
}//End.
</script>





<script type="text/javascript">






function getMap(elImage) {
// Be sure a map is specified for the image.
if (null != elImage.getAttribute('usemap')) {
// Remove the leading # from the bookmark.
var strMap = elImage.getAttribute('usemap').substring(1);
// Return the element with the specified name.
return strMap;
}
return null;
}

function zoomImage(elImage, amount) {
// Expand the image the specified amount.
var elMap = getMap(elImage);
var zxcp=elImage.parentNode;
var zxcoldx=(elImage.width-zxcp.offsetWidth)/2;
var zxcoldy=(elImage.height-zxcp.offsetHeight)/2;
if (elImage.width * amount<zxcp.offsetWidth||elImage.height * amount<zxcp.offsetHeight) return;
elImage.width *= amount;
elImage.height *= amount;
elImage.style.left=parseInt(elImage.style.left)-(elImage.width-zxcp.offsetWidth)/2+zxcoldx+'px';
elImage.style.top=parseInt(elImage.style.top)-(elImage.height-zxcp.offsetHeight)/2+zxcoldy+'px';
// If an image map is available, scale it too.
if (null != elMap) {
elMap=document.getElementsByName(elMap)[0];
for (var intLoop = 0; intLoop < elMap.areas.length; intLoop++) {
var elArea = elMap.areas[intLoop];
// Break the coordinates string into an array.
var coords = elArea.coords.split(",");
var scaledCoords = "";
// Rebuild the new scaled string.
for (coord in coords) {
scaledCoords += (coords[coord] * amount) + ",";
}

// Put the scaled coordinates back into the map.
elArea.coords = scaledCoords;
}
}
}




</script>









</head>

<BODY onload="">




<DIV ID="myDiv"
style="margin-bottom: 600px;margin-top: 80px; margin-left: 300px; margin-right: 200px; text-align: center;BORDER-RIGHT: #ffffff 1px; BORDER-TOP: #ffffff 1px; Z-INDEX: 1; VISIBILITY: visible; overflow:hidden; BORDER-LEFT: #ffffff 1px; WIDTH: 200px; BORDER-BOTTOM: #ffffff 1px; POSITION:absolute; top:10px;right:50px; HEIGHT: 200px; BACKGROUND-COLOR: #ffffff; layer-background-color: #FFFFFF ; padding:0" >

<IMG src="http://www.vicsjavascripts.org.uk/StdImages/One.gif" id="img1" class="dragclass" style="position:relative;left:0px;top:0px;" name=imageName usemap="#map1" width="200" height="200" border="0" >

</div>

<map name="map1" ></map>

<p>
<input value="Zoom In" onclick="zoomImage(document.getElementById('img1'), 2); " id="zoomin" type="button">
<input value="Zoom Out" onclick="zoomImage(document.getElementById('img1'), .5); " id="zoomout" type="button">
</p>
<p>


</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@Laith_jodehauthorNov 11.2008 — thanks vwphillips for help,but your code accomplished half of the mission since

after zooming and drag any specific portion of image to center it will not zoom centrally in all direction...if you try the link I gave:

http://jibbering.com/routeplanner/#

...then if you drag any

part of it to the center after zooming to any certain level ; it will zoom equivalently in all directions....any clue?!!
Copy linkTweet thisAlerts:
@vwphillipsNov 12.2008 — [CODE]function zoomImage(elImage, amount) {
// Expand the image the specified amount.
var elMap = getMap(elImage);
var zxcp=elImage.parentNode;
if (!elImage.save) elImage.save=elImage.width;
if (elImage.width * amount<elImage.save) return;
elImage.width *=amount;
elImage.height *=amount;
elImage.style.left=parseInt(parseInt(elImage.style.left)-zxcp.offsetWidth/2)*amount+zxcp.offsetWidth/2+'px';
elImage.style.top=parseInt(parseInt(elImage.style.top)-zxcp.offsetHeight/2)*amount+zxcp.offsetHeight/2+'px';
// If an image map is available, scale it too.
if (null != elMap) {
elMap=document.getElementsByName(elMap)[0];
for (var intLoop = 0; intLoop < elMap.areas.length; intLoop++) {
var elArea = elMap.areas[intLoop];
// Break the coordinates string into an array.
var coords = elArea.coords.split(",");
var scaledCoords = "";
// Rebuild the new scaled string.
for (coord in coords) {
scaledCoords += (coords[coord] * amount) + ",";
}

// Put the scaled coordinates back into the map.
elArea.coords = scaledCoords;
}
}
}
[/CODE]
Copy linkTweet thisAlerts:
@Laith_jodehauthorNov 12.2008 — You are super...thax for this great work VWPhillips
×

Success!

Help @Laith_jodeh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...