Last week I was reading a nice article by Seifi explaining how to clip an image in a web page by using available CSS techniques. I did like the idea of clipping images. Sometime there is no need to show the whole image on a page, especially if you want to save space.
How?
Example
<img src="castle.jpg" id="clipit" alt="Clipped castle image" width="300" height="225" clipwidth="136" clipheight="105" clipleft="82" cliptop="50" />
As you can see, I have used some custom properties to the img tag, which will be used by javascript during the clipping process. In order to get the image clipped I have written a javascript function which can be called.
clipImage( 'id-of-image', 1);
This function will take care of it all and it will render the clipped image with the given parameters. I didnt spend much time on the code and it is quick and dirty. Maybe it would be an idea create a jQuery plugin for it.
The demo page showing the image clipping can be found here.
Please look at the source to see the implementation.
Feedback/Comments
If you have any questions or remarks about this code, you can always contact me.
No comments:
Post a Comment