473,626 Members | 3,443 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript slide show: Click the picture and go to next picture?

I know how to use buttons to go to the next and previous picture in
slide show, but i want to change it so when the user clicks the picture
instead of button, the script shows the next phicture.

How can i change it?
Any suggesstions?

Thanks!

<script language="JavaS cript">
<!--
var x = 1
images = new Array
images[1] = "images/AidaL.jpg"
images[2] = "images/mclaren10S.jpg"
images[3] = "images/lotus6S.jpg"
images[4] = "images/SENNAS.jpg"
images[5] = "images/arytonsennaS.jp g"
//add additional images here as required

function backimg(){
if (x != 1){
document.image1 .src = images[x-1]
x-- }
}
function fwdimg(){
if (x != 5){ //Change the 5 here to your total number
document.image1 .src = images[x+1]
x++ }
}
// -->
</script>

<IMG SRC="images/AidaL.jpg" name="image1" border=0><br>
<a href="" onClick="backim g();return false;"><img src=sback.gif
border=0 width=30 height=16></a>
<A href="" onClick="fwdimg (); return false;"><img src="ssfwd.gif"
border=0 width=30 height=16></a>
--------------------------------------------------------------------------------

Jul 23 '05 #1
8 7170
ma*****@hotmail .com wrote:
I know how to use buttons to go to the next and previous picture in
slide show, but i want to change it so when the user clicks the picture
instead of button, the script shows the next phicture.

How can i change it?
Any suggesstions?

You may need to preload images:

<script type="text/javascript">
x = -1;
images =["ann.jpg","dave .jpg","joe.jpg" ,"gary.jpg","le e.jpg"]

function stepimg(){
if(x==images.le ngth)x=-1;
document.image1 .src =images[x++];
}

</script>
<a href="#" onClick="stepim g()">
<img src="ann.jpg" name="image1" width="120" height="150" border=0>
</a>
Jul 23 '05 #2
Mick White <mw***********@ rochester.rr.co m> wrote in message
news:IX******** *********@twist er.nyroc.rr.com ...
ma*****@hotmail .com wrote:

<script type="text/javascript">
x = -1;
images =["ann.jpg","dave .jpg","joe.jpg" ,"gary.jpg","le e.jpg"]

function stepimg(){
if(x==images.le ngth)x=-1;
document.image1 .src =images[x++];
}


I don't want to be negative in this 'post', but perhaps you would you like
to revise that.
--
Stephen Chalmers


Jul 23 '05 #3
Stephen Chalmers wrote:
Mick White wrote
<script type="text/javascript">
x = -1;
images =["ann.jpg","dave .jpg","joe.jpg" ,"gary.jpg","le e.jpg"]

function stepimg(){
if(x==images. length)x=-1;
document.imag e1.src =images[x++];
}

I don't want to be negative in this 'post', but perhaps you would you like
to revise that.
--


It should work, but I would preload the images.
Mick
Jul 23 '05 #4

<ma*****@hotmai l.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I know how to use buttons to go to the next and previous picture in
slide show, but i want to change it so when the user clicks the picture
instead of button, the script shows the next phicture.

How can i change it?
Any suggesstions?

Thanks!

<script language="JavaS cript">
<!--
var x = 1
images = new Array
images[1] = "images/AidaL.jpg"
images[2] = "images/mclaren10S.jpg"
images[3] = "images/lotus6S.jpg"
images[4] = "images/SENNAS.jpg"
images[5] = "images/arytonsennaS.jp g"
//add additional images here as required

function backimg(){
if (x != 1){
document.image1 .src = images[x-1]
x-- }
}
function fwdimg(){
if (x != 5){ //Change the 5 here to your total number
document.image1 .src = images[x+1]
x++ }
}
// -->
</script>

<IMG SRC="images/AidaL.jpg" name="image1" border=0><br>
<a href="" onClick="backim g();return false;"><img src=sback.gif
border=0 width=30 height=16></a>
<A href="" onClick="fwdimg (); return false;"><img src="ssfwd.gif"
border=0 width=30 height=16></a>
-------------------------------------------------------------------------- ------

I would consider if this would be 'expected' behavior. If the user is used
to clicking a picture to enlarge it or select it this might be annoying.
Maybe use arrows or img controls to move forward or backwards. Like you
would see in most slide show and image viewers.
Jimbo
Jul 23 '05 #5


Mick White <mw***********@ rochester.rr.co m> wrote in message
news:gf******** ********@twiste r.nyroc.rr.com. ..>
It should work, but I would preload the images.
Mick x = -1;
images =["ann.jpg","dave .jpg","joe.jpg" ,"gary.jpg","le e.jpg"]

function stepimg(){
if(x==images. length)x=-1;

document.image 1.src =images[x++];
}


What is the value of x in the subscript?

--
Stephen Chalmers


Jul 23 '05 #6
Stephen Chalmers wrote:
Mick White <mw***********@ rochester.rr.co m> wrote in message
news:gf******** ********@twiste r.nyroc.rr.com. ..>
It should work, but I would preload the images.
Mick


x = -1;
images =["ann.jpg","dave .jpg","joe.jpg" ,"gary.jpg","le e.jpg"]

function stepimg(){
if(x==images .length)x=-1;


document.imag e1.src =images[x++];
}

What is the value of x in the subscript?


document.image1 .src =images[++x];

Would be better...
Mick
Jul 23 '05 #7
"Mick White" <mw***********@ rochester.rr.co m> wrote in message
news:Pp******** *********@twist er.nyroc.rr.com ...
Stephen Chalmers wrote:
Mick White <mw***********@ rochester.rr.co m> wrote in message
news:gf******** ********@twiste r.nyroc.rr.com. ..>
It should work, but I would preload the images.
Mick


x = -1;
images =["ann.jpg","dave .jpg","joe.jpg" ,"gary.jpg","le e.jpg"]

function stepimg(){

if(x==image s.length)x=-1;

document.ima ge1.src =images[x++];
}

What is the value of x in the subscript?


document.image1 .src =images[++x];

Would be better...
Mick


Taking your modification to the existing source:

x = -1;
images = ["ann.jpg","dave .jpg","joe.jpg" ,"gary.jpg","le e.jpg"];
function stepimg()
{
if (x == images.length)
{
x = -1;
}

document.image1 .src = images[++x];
}

We now have a situation where a call to stepimg() will attempt to access
images[5], which returns undefined. You'd need to modify the condition
as: if (x == images.length - 1) in order to avoid this. I'm also not a
big fan of global variables to track the next image, I'd prefer the
images Array to "know" it's next position. So something like this would
be preferable (to me):

var images = ["ann.jpg", "dave.jpg", "joe.jpg", "gary.jpg", "lee.jpg"];
function stepimg()
{
document.images['image1'].src = images[images.nextImag e =
images.nextImag e || 0];
images.nextImag e = (images.nextIma ge + 1) % images.length;
}

--
Grant Wagner <gw*****@agrico reunited.com>
comp.lang.javas cript FAQ - http://jibbering.com/faq

Jul 23 '05 #8
Grant Wagner wrote:
[snip]
So something like this would
be preferable (to me):

var images = ["ann.jpg", "dave.jpg", "joe.jpg", "gary.jpg", "lee.jpg"];
function stepimg()
{
document.images['image1'].src = images[images.nextImag e =
images.nextImag e || 0];
images.nextImag e = (images.nextIma ge + 1) % images.length;
}

Elegant...
Thanks.
Mick
Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2048
by: TrvlOrm | last post by:
HI There, I have been struggling with JavaScript code for days now, and this is my last resort! Please help... I am trying to create a JavaScript slide show with links for Next Slide, Previous Slide and Home Slide. Is it possible for you to view my page and tell me what I am doing wrong. I have looked at this page for hours and can't figure it out, I
7
3052
by: 7mary4 | last post by:
I am working on a kiosk for a museum, we will be using firefox as the browser, with windows, and a touch screen. We'd like to create a slide show of a small portfolio when the visitors click down to the lowest level of the collection. For instance, after choosing Africa, then Sudan, they will choose what they would like to look at: jewelry, tapestry, metals, etc. When they choose tapestry, there will be groups of ten thumbnails. These...
3
2344
by: B Maxey | last post by:
I am storing images in a database and need a way to browse those files. I can load the files into an image list or whatever the control needs, but I need a control. It doesn't seem that any of the standard window controls would work, but I am thinking I can just draw all the images on an panel (or a browser form for that matter). Does anyone have any advice?
4
3470
by: Doug van Vianen | last post by:
Hi, I have the following coding on a web page. It causes two pictures (pic1.jpg and pic2.jpg) to show, one above the other and then when one clicks on the top picture is squeezes to the left (as its width is reduced) to show the bottom picture. Then when the bottom picture is clicked the top picture expands to the right to cover the bottom picture again.
22
5114
by: bevoldjling | last post by:
Hi ! I need some help in putting together a website for our family gathering. Although I'm still pretty "green", I don't think what I need requires terribly advanced skills ...except for one area that has me right baffled. I want to put up a photo album slideshow but I want to stay away from Flash & Javascript. It just seems that anytime I use them, somebody
4
1980
by: Mike Chen | last post by:
Dear all, I made a c# program for my friend's wedding. It slides all photos in specified folder automatically. To roll the pictures smoothly I firstly scan and store all pictures in RAM and push one by one to PictureBox control and display it when the Timer control ticks. Coding like this: ------------------------------------------------------ IList<Imagephotoes = new List<Image>();...
3
5246
by: Beamer | last post by:
Hi I am trying to build a roating slide effect in javascript. Basically, I have a list like below <ul id="slideShowCnt"> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li> <li id="slide0"><img .../></li>
3
3850
by: krzysztof.murkowski | last post by:
Hi, I have problem with JavaScript for gallery of images. From the overview page with thumbnails, after a click on the small picture, the subpage 'slide_show.html' is called, with a number of picture as parameter for example: <a href=slide_show.html?nb=2> (The code is at the end of this post)
0
8268
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8202
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,...
0
8641
jinu1996
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...
1
8366
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,...
0
8510
tracyyun
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...
1
6125
isladogs
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...
0
4093
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...
1
2628
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1512
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.