Move an image within a clip region

P

peter.chase

In my Web application, a have an image within a DIV. One of the allowed
user gestures is to drag the image with the mouse. When dragging, parts
of the image that would otherwise be displayed outside the DIV should
be clipped.

I had no trouble at all achieving this on FireFox and Safari. But I
can't get Internet Explorer to do the clipping; it always shows the
whole image, including the bits outside the DIV.

Here's the HTML: -

<div id="RoamImageDiv">
<img id="RoamDynamicImage" src="...">
</div>

Here's the CSS: -

#RoamImageDiv
{
text-align: center ;
vertical-align: middle ;
padding: 0px ;
margin: 0px ;
border: 0px ;
overflow: hidden ;
}

#RoamDynamicImage
{
cursor: default ;
position: relative ;
}

The JavaScript code handling mouse events simple adjusts the
"style.left" and "style.top" of the image element, to make the image
move as the mouse is dragged. This works on all the browsers (except
the clipping thing on IE, of course).

It is my understanding that the situation might be better if I used
"absolute" positioning. However, the position is not really fixed, so
"absolute" would be very difficult, if not impossible, to use in this
situation. I did try dynamically switching to "absolute", after letting
the browser do the layout with "relative", but this totally confused
all the browsers!

Any suggestions?
 
M

marss

(e-mail address removed) напиÑав:
I had no trouble at all achieving this on FireFox and Safari. But I
can't get Internet Explorer to do the clipping; it always shows the
whole image, including the bits outside the DIV.


Specify DIV size

#RoamImageDiv
{
....
height:150px;
width:50px;

}
 
P

peter.chase

marss said:
(e-mail address removed) напиÑав:



Specify DIV size

#RoamImageDiv
{
...
height:150px;
width:50px;

}

Thanks.

I have only tried it with the height and width hard-coded in the CSS,
like you have shown. That works, but I cannot actually do it that way
for real, because the size varies. I will now try setting height and
width programmatically and see if it still works.
 
P

peter.chase

Thanks.

I have only tried it with the height and width hard-coded in the CSS,
like you have shown. That works, but I cannot actually do it that way
for real, because the size varies. I will now try setting height and
width programmatically and see if it still works.

Yep, works perfectly. Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,481
Members
44,900
Latest member
Nell636132

Latest Threads

Top