Can someone help me out with this.
Here is what i am trying to do. I have an image of size 310x310. Initially i am displaying only 50x50 using clip property. Later using setTimeout property i am trying to get the entire image so that it looks like animation. But this doesn't happen with the code below
[HTML]<html>
<head>
<style type="text/css">
.img1
{
position:absolu te;
clip:rect(0px 50px 50px 0px)
}
</style>
<script type="text/javascript">
function start() {
var x=document.getE lementById("img 1");
x.style.clip.ri ght+=10;
x.style.clip.bo ttom+=10;
if (x.style.clip.r ight<310)
setTimeout("sta rt()",10);
else return;
}
</script>
</head>
<body onLoad="start() ;">
<p>The clip property is here cutting an image:</p>
<p><img id="img1" class="img1" border="0" src="Kiva_Logo. jpg" width="310" height="310"></p>
</body>
</html>[/HTML]
5 5975 acoder 16,027
Recognized Expert Moderator MVP
There's no clip.right/bottom. Set the whole clip each time. See this link. Don't forget the measurements (e.g. "px").
Sorry i was late in replying. Next time i would make it soon
Thanks for the help
The link was much useful. Here are some modifications that i made and its working fine
[HTML]<html>
<head>
<style type="text/css">
.img1
{
position:absolu te;
clip:rect(0px 50px 50px 0px)
}
</style>
<script type="text/javascript">
var n=1;
function start() {
var x=document.getE lementById("img 1");
var i=0;
if (n<8) {
switch(n)
{
case 1:
x.style.clip="r ect(0px,50px,50 px,0px)";
break;
case 2:
x.style.clip="r ect(0px,100px,1 00px,0px)";
break;
case 3:
x.style.clip="r ect(0px,150px,1 50px,0px)";
break;
case 4:
x.style.clip="r ect(0px,200px,2 00px,0px)";
break;
case 5:
x.style.clip="r ect(0px,250px,2 50px,0px)";
break;
case 6:
x.style.clip="r ect(0px,300px,3 00px,0px)";
break;
case 7:
x.style.clip="r ect(0px,350px,3 50px,0px)";
break;
default:
break;
}
setTimeout("sta rt()",200);
n++;
i++;
}
else {
return;
}
}
</script>
</head>
<body onLoad="start() ;">
<p>The clip property used to cut the image:</p>
<p><img id="img1" class="img1" border="0" src="Kiva_Logo. jpg" width="310" height="310"></p>
</body>
</html>
[/HTML]
But i need to optimize this code.
I need to avoid switch statements and use a variable 'z' such that i have
z=0;
x.style.clip="r ect(0px,z,z,0px )" ;
z++ ;
hence i can increment the clipping pixel by pixel and increasing the speed would make it look like animation.
But the above code(using variable) is not possible. I also tried using arrays and eval. It didn't work.
Can you suggest any method to dynamically increase the clip attributes by using any variable or anything as such.
Thanks for the help
acoder 16,027
Recognized Expert Moderator MVP
Try this: - x.style.clip="rect(0px,"+(n*50)+"px,"+(n*50)+"px,0px)";
Ps. please use [code] tags when posting code. Thanks!
The code works perfect with this line - x.style.clip="rect(0px,"+(n*50)+"px,"+(n*50)+"px,0px)";
The variable should be enclosed between "+" signs when used as an attribute value. That's the lesson for me.
Thanks a lot.
acoder 16,027
Recognized Expert Moderator MVP
Glad you got it working and a lesson learnt!
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: RIck Measham |
last post by:
I pop up a window with a picture in it, however the picture can be very
large. So here's what I want to do: Pop up a mindow with the picture
clipped to the size of the window, then place a scaled version of the
picture on top of it. Thus it will look like this:
+------------------------+
| WINDOW |
+------------------------|
| |
| |
|
by: Jeff Thies |
last post by:
I'm having trouble clipping an image. My understanding is that this is all
I should need:
<img src="test_img.jpg" style="clip: rect(10px 10px 10px 10px)" alt="alt">
Although I've seen this as a comma seperated list.
This has no effect whatesoever. What am I doing wrong?
Jeff
|
by: Kimmo R. M. Hovi |
last post by:
Currently I have defined:
-- clip clip --
<form method="post" action="xx"
enctype="application/x-www-form-urlencoded">
<input type="image" name="Function 1" src="image1.gif" border="0"
title="1">
|
by: Anand Ganesh |
last post by:
HI All,
I have an Image. I want to clip a portion of it and copy to another image.
How to do this? I know the bounding rectangle to clip.
Any suggestions please.
Thanks for your time and help.
Regards
|
by: Robert W. |
last post by:
In my Winforms app I'm trying to get an image's background to appear
transparent on a form that has a gradient background. So I added a
PictureBox and then attempted to add a custom paint command for the
PictureBox. But it's not working. Here's the code I've written:
public void InitializeLinearGradients()
{
this.Paint += new PaintEventHandler(PaintClient);
this.SizeChanged += new EventHandler(SizeClient);
pictureLogo.Paint += new...
| |
by: Csaba Gabor |
last post by:
If I take a look at a site that has a heirarchical directory structure
(e.g. http://www.treemenu.org/), then on the left there are always(?)
some small images on the left, corresponding to '+', '-', '|-', and
'|_'. By abutting these, you get a "pretty" "tree" representation.
However, if the user alters their font size (especially to a larger
size) from what the site designer figured, then these images will no
longer lie flush/close to...
|
by: Brian |
last post by:
Using A2K I have an image control on a report and use code to set the
image.picture to the required jpg. 3 of the jpgs resize properly but
2 do not - they display much smaller than the image control. The
problem jpgs were originally created as line drawings in Word. They
were then copy and pasted to Paint where they were saved as jpg files.
Sizemode is set to stretch.(have tried clip and zoom but no better). I
cannot find any way to...
|
by: Keith G Hicks |
last post by:
In MS Access image controls there's a property setting for "Size Mode" -->
Clip, Zoom or Stretch. I don't see any similar property in an asp image
control. When I have an image on a page, it seems to Stretch no matter what.
If an image is displayed that has different proportions than the image
control itself, the image is distorted. I need a "Zoom" setting (not to zoom
in and out). How can this be done?
Thanks,
Keith
|
by: Chris Riesbeck |
last post by:
I have an image with a class and the class defines a clip rectangle.
In Firefox 2 and 3, and Opera 9, I can access the rectangle with
document.defaultView.getComputedStyle().
But that doesn't seem to work in Safari for Windows 3, nor when I use
image.currentStyle.clip in IE 7.
Is there a way to do this in those browsers? Am I doing something stupid?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |