Click to See Complete Forum and Search --> : Rotating Images
Uwang
05-21-2003, 05:43 PM
Not sure if this has been posted elsewhere so I guess I will ask it anyway. If it has already been answer just post a link to the thread please.
Question: Does anyone know of a script/code that allows a user to select an image (one that already has the script attached to it that allows them to move the imaget around the page freely), click a button and allow them to ROTATE that image, say 90 degrees, each time they press it?
Thanks for any advice you can give and for your time!
This is only a rough idea though it does work on images that are the same height and width.
Have a play.
<HTML>
<HEAD>
<TITLE>Document Title</TITLE>
</HEAD>
<BODY>
<SCRIPT language=JavaScript1.2>
<!--
var moving=false
function Dragnow(){
curposx=event.clientX // Cursorx Start Position
curposy=event.clientY // Cursory Start Position
objectx=moveobject.style.pixelLeft // Objectx Start Position
objecty=moveobject.style.pixelTop // Objecty Start Position
moving=true
document.onmousemove=Moveto
}
function Moveto(){
if (moving==true){
document.all.moveobject.style.pixelLeft=event.clientX-(curposx-objectx) // Objectx New Pos
document.all.moveobject.style.pixelTop=event.clientY-(curposy-objecty) // Objecty New Pos
return false
}
}
if (document.all){
document.onmouseup=new Function("moving=false")
}
// -->
</SCRIPT>
<SCRIPT>
i = 0;
deg2rad = Math.PI / 180;
function SetRotation(deg){
rad = deg * deg2rad;
costheta = Math.cos(rad);
sintheta = Math.sin(rad);
moveobject.filters.item(0).M11 = costheta;
moveobject.filters.item(0).M12 = -sintheta;
moveobject.filters.item(0).M21 = sintheta;
moveobject.filters.item(0).M22 = costheta;
}
function DoAnimation(){
//moveobject.onfilterchange = DoAnimation;
i += 90;
if (i > 359){
i = 0;
moveobject.onfilterchange = null;
}
SetRotation(i)
}
</SCRIPT>
<DIV id="moveobject" style="position:absolute; left:245px; top: 115px; width:80px;border:2 solid #A050F0;background-color:#000000;color:gold;cursor: hand" onmousedown="Dragnow()" style="FILTER: progid:DXImageTransform.Microsoft.Matrix(sizingmethod='auto expand')">
<img src="pic1.jpg" width="100" height="100">
</DIV>
<form>
<input type="button" value="Rotate" onclick="DoAnimation()">
</form>
</BODY>
</HTML>
Uwang
05-25-2003, 01:24 AM
I tried it and it does work for one image the problem is how do i get it to work with numerous images and still only use one button? I was hoping that there was some kinda of command/script language that would allow something like: When this image is selectd (Focused on) and this button is pushed then rotate 90 degrees! I know this is asking a lot and again I appreciate your time and help! Thank you!!
Have a play with the files in the zip
Uwang
05-25-2003, 12:18 PM
That is like exactly what i needed. What do I have to add to the code to allow more images? Thank you, thank you, thank you!
Looking at the image places you will see:
<img name="picture1"
<img name="picture2"
<img name="picture3"
<img name="picture4"
and in each of the images onmousedown event:
set_values(picture1,1)
set_values(picture2,2)
set_values(picture3,3)
set_values(picture4,4)
So for a 5th image you would go:
<img name="picture5"
and
set_values(picture5,5)
Also in the script there is an array
angle=new Array()
angle[0]=0
angle[1]=0
angle[2]=0
angle[3]=0
angle[4]=0
Here you add
angle[5]=0
to the list
So your new image entry would be
<img id="picture5" class="dragme" src="new_image.gif" width="100" height="50" style="position:absolute; left:550px; top:115px; width:80px" onmousedown="Dragnow();set_values(picture5,5)">
Uwang
05-25-2003, 06:46 PM
Do I have to have this: style="position:absolute; left:550px; top:115px; width:80px" in the img code as I was putting the images in a table and it is really difficult to get the riht coor to place it in the proper cell?
I figured out how to add pictures about 10 minutes after I posted my previous message. Now im trying to get it to work in a table with images!
If you put the images in a table you will not be able to drag them around the page.
Also the rotation of the images is not around its center which will be more obvious if table borders are visible
Uwang
05-26-2003, 01:45 PM
You can see what I was able to put together here (http://www25.brinkster.com/ewim0/NUP.html) . It was a pain and I am sure there is a better way to do it. Also do you know what I would have to add to the code so I could "flip" the images across their horizontal/vertical axis (seperately of course)? Thanks for the info on the table I will probably just remove the table all togther and let the images goes as they are!
Please try the file in the zip
Uwang
05-26-2003, 09:01 PM
You are the best man. Thank you so much for your time and help!! :)