faqts : Computers : Programming : Languages : JavaScript : Images

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

23 of 35 people (66%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How do I hide certain parts of an image; How do I emulate a crop with Javascript?

Dec 19th, 2005 03:20
Trung Ha Pham, Randy Harmelink, Jake Carlson,


Although you could use JavaScript to dynamically set/alter the 
width/height/top/left style characteristics, you only need HTML/CSS to 
clip the image:
<html>
<style><!--
   .clip    {
            width        : 100;
	    height       : 100;
	    overflow     : hidden;
            }
   .clip2   {
            position     : relative;
            top          : -100;
            left         : -100; 
            }		
   --></style>
<body>
<span class=clip><img class=clip2 src="image.jpg"></span>
</body>
</html>
I only use IE, so I'm not sure how compatible this is with other 
browsers.
Above work for IE, I asked this question in http://www.experts-exchange.
com/ and got result below
<html>
<body>
<div style="OVERFLOW: hidden; WIDTH: 78px; position: relative; HEIGHT: 
78px">
<img src="http://www.faqts.com/images/faqts.gif" id="img1" style="LEFT: 
-10px; POSITION: relative; TOP: -10px">
</div>
</body>
</html>
Work for IE 6.0, Opera 7.x, Fire Fox 1.x