Click here to Skip to main content
15,921,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I am searching a better obtion to implement image rotator functionality in one of my asp.net web application. I got one solution using jquery and it is working fine(http://www.xdevsoftware.com/blog/post/jquery-Image-Rotator-for-ASPNET.aspx#comment).Could anyone please let us know if i can use any other control to use same functionality.

If anyone already used this code, could you please let me know pros and cons of that.

Can i use AnimationExtender (Ajaxtoolkit control) to implement this functionality. Could you please let me know which one will be better. Performance is much important in my case.




Regards,
Rajesh
Posted

1 solution

Hiiii



<code><pre lang="xml">There are many ways to create Image Rotator in JavaScript .I write two simple examples to create an Image rotator in JavaScript.
My first Program:
Step 1: First we create an image(img1) with the help of &lt;img&gt; tag. and place it in the &lt;body&gt; tag:-&gt;
&lt;body onload=&quot;show()&quot;&gt;
&lt;img id=&quot;img1&quot; width=&quot;120px&quot; /&gt;
&lt;/body&gt;
Note: Here we call a js function(show()) on the onload event.
Step 2: Create a javascript function(show()) in the &lt;head&gt; tag:-&gt;
&lt;script language=&#39;javascript&#39;&gt;
function show()
{
document.getElementById(&#39;img1&#39;).src=&quot;Water lilies.jpg&quot;;
setTimeout(&quot;show2()&quot;,1000);
}
function show2()
{
document.getElementById(&#39;img1&#39;).src=&quot;Winter.jpg&quot;;
setTimeout(&quot;show3()&quot;,1000);
}
function show3()
{
document.getElementById(&#39;img1&#39;).src=&quot;Sunset.jpg&quot;;
setTimeout(&quot;show4()&quot;,1000);
}
function show4()
{
document.getElementById(&#39;img1&#39;).src=&quot;Blue hills.jpg&quot;;
setTimeout(&quot;show()&quot;,1000);
}
&lt;/script&gt;
Here we get the Id of the image(img1) with the help of getElementById (The getElementById() method accesses the element with the specified id).
and sets the source(src) of the img1. Here we create many functions and call it with the help of setTimeout Method of javascript.
My second Program:
Here we sets the imge on the basis of the onmouseover event of the particular Table&#39;s Text and sets the image and there description on the basis of it.
Step 1: First We create a table in the &lt;body&gt; tag and sets an image(img1) and multiple &lt;p&gt; tags in the table rows:-&gt;
&lt;table style=&quot;border:1px solid Black&quot;&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;img id=&quot;img1&quot; src=&quot;Sunset.jpg&quot; width=&quot;120px&quot; /&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;p id=&quot;pmain&quot;&gt; &lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;table style=&quot;width:140px&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;td1&quot; align=&quot;center&quot; style=&quot;border:1px solid Black&quot; onmouseover=&quot;show1()&quot; onmouseout=&quot;hide1()&quot;&gt;
&lt;p id=&quot;p1&quot;&gt;Image1&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td id=&quot;td2&quot; align=&quot;center&quot; style=&quot;border:1px solid Black&quot; onmouseover=&quot;show2()&quot; onmouseout=&quot;hide2()&quot;&gt;
&lt;p id=&quot;p2&quot;&gt;Image2&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td id=&quot;td3&quot; align=&quot;center&quot; style=&quot;border:1px solid Black&quot; onmouseover=&quot;show3()&quot; onmouseout=&quot;hide3()&quot;&gt;
&lt;p id=&quot;p3&quot;&gt;Image3&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td id=&quot;td4&quot; align=&quot;center&quot; style=&quot;border:1px solid Black&quot; onmouseover=&quot;show4()&quot; onmouseout=&quot;hide4()&quot;&gt;
&lt;p id=&quot;p4&quot;&gt;Image4&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
Here we set the style and call functions on the onmouseover and onmouseout event.
Step 2: Create javascript functions in the &lt;head&gt; tag:-&gt;
&lt;script language=&#39;javascript&#39;&gt;
function show1()
{
document.getElementById(&#39;img1&#39;).src=&quot;Winter.jpg&quot;;
document.getElementById(&quot;p1&quot;).style.fontStyle=&quot;italic&quot;;
document.getElementById(&quot;td1&quot;).style.background=&quot;Red&quot;;
document.getElementById(&quot;pmain&quot;).innerHTML=&quot;Image1&quot;;
}
function hide1()
{
document.getElementById(&quot;p1&quot;).style.fontStyle=&quot;normal&quot;;
document.getElementById(&quot;td1&quot;).style.background=&quot;White&quot;;
document.getElementById(&quot;pmain&quot;).innerHTML=&quot;&quot;;
}
function show2()
{
document.getElementById(&#39;img1&#39;).src=&quot;Sunset.jpg&quot;;
document.getElementById(&quot;p2&quot;).style.fontStyle=&quot;italic&quot;;
document.getElementById(&quot;td2&quot;).style.background=&quot;Red&quot;;
document.getElementById(&quot;pmain&quot;).innerHTML=&quot;Image2&quot;;
}
function hide2()
{
document.getElementById(&quot;p2&quot;).style.fontStyle=&quot;normal&quot;;
document.getElementById(&quot;td2&quot;).style.background=&quot;White&quot;;
document.getElementById(&quot;pmain&quot;).innerHTML=&quot;&quot;;
}
function show3()
{
document.getElementById(&#39;img1&#39;).src=&quot;Water lilies.jpg&quot;;
document.getElementById(&quot;p3&quot;).style.fontStyle=&quot;italic&quot;;
document.getElementById(&quot;td3&quot;).style.background=&quot;Red&quot;;
document.getElementById(&quot;pmain&quot;).innerHTML=&quot;Image3&quot;;
}
function hide3()
{
document.getElementById(&quot;p3&quot;).style.fontStyle=&quot;normal&quot;;
document.getElementById(&quot;td3&quot;).style.background=&quot;White&quot;;
document.getElementById(&quot;pmain&quot;).innerHTML=&quot;&quot;;
}
function show4()
{
document.getElementById(&#39;img1&#39;).src=&quot;Blue hills.jpg&quot;;
document.getElementById(&quot;p4&quot;).style.fontStyle=&quot;italic&quot;;
document.getElementById(&quot;td4&quot;).style.background=&quot;Red&quot;;
document.getElementById(&quot;pmain&quot;).innerHTML=&quot;Image4&quot;;
}
function hide4()
{
document.getElementById(&quot;p4&quot;).style.fontStyle=&quot;normal&quot;;
document.getElementById(&quot;td4&quot;).style.background=&quot;White&quot;;
document.getElementById(&quot;pmain&quot;).innerHTML=&quot;&quot;;
}
&lt;/script&gt;
Here we sets the src property of image(img1) with the help of id and sets the style of &lt;td&gt; and &lt;p&gt; tags and the innerHTML property of &lt;p&gt; tag on the basic of Id .Here we get the Id with the help of getElementById (The getElementById() method accesses the element with the specified id).</pre></code>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900