I have created some simple code to allow me to flip through thumbnail
images via "Previous" and "Next" links. The idea is that I can have
multiple sets of images that can be scrolled through, via
document.images[<n>].src.
However, the problem is, once the "last" image is reached, the code
refuses to go back to the "first" image.
Help is appreciated.
<title>Test Page</title>
</head>
<script language="javas cript">
<!--
var imagearray1 = new Array("./image1.gif","./image2.gif");
var lastelement1 = imagearray1.len gth - 1;
var currentelement1 = 0;
function showpicture(ima geindex, imagearray, current)
{
document.images[imageindex].src=imagearray[current];
}
function nextpicture(ima geindex, imagearray, current, last)
{
current += 1;
if (current>last)
{
current = 0;
}
showpicture(ima geindex, imagearray, current);
}
function prevpicture(ima geindex, imagearray, current, last)
{
current -= 1;
if (current < 0)
{
current = last;
}
showpicture(ima geindex, imagearray, current);
}
-->
</script>
<body>
<img src="image1.gif "><br>
<a href="javascrip t:prevpicture(0 , imagearray1, currentelement1 ,
lastelement1)"> Previous</a><br>
<a href="javascrip t:nextpicture(0 , imagearray1, currentelement1 ,
lastelement1)"> Next</a><br>
</body> 1 1253
On 29 Jan 2004 07:09:31 -0800, Jason Ferguson
<fe***********@ sbcglobal.net> wrote: I have created some simple code to allow me to flip through thumbnail images via "Previous" and "Next" links. The idea is that I can have multiple sets of images that can be scrolled through, via document.images[<n>].src.
However, the problem is, once the "last" image is reached, the code refuses to go back to the "first" image.
If you tried to test the script as it is with more than two images, you
would find bigger issues than not being able to wrap between the first and
last images.
Declaration:
var currentelement1 = 0;
Definition:
function nextpicture(ima geindex, imagearray, current, last) {
current += 1;
if (current>last) {
current = 0;
}
showpicture(ima geindex, imagearray, current);
}
Call:
nextpicture(0, imagearray1, currentelement1 , lastelement1)
When called, nextpicture is passed 0 for the third argument (current in
the function). This value is modified in the function, but currentelement1
will still remain 0; the variable is not passed by reference. The simple
solution here is to use the global variable directly.
As for the non-functional wrapping, you're forgetting how arrays are
indexed: 0 to n-1. You are treating them as 0 to n. The fix here is:
if( current == last ) current = 0;
and
if( 0 > current ) current = last - 1;
for nextpicture and prevpicture, respectively.
<a href="javascrip t:prevpicture(0 , imagearray1, currentelement1 , lastelement1)"> Previous</a><br> <a href="javascrip t:nextpicture(0 , imagearray1, currentelement1 , lastelement1)"> Next</a>
Finally, change the above links to use the onclick attribute instead of
the JavaScript pseudo-protocol in the href attribute. This doesn't have
any direct bearing on the problem, but it is a bad habit (for the most
part), and should be avoided. It is covered in the group FAQ: http://jibbering.com/faq/#FAQ4_24
Mike
--
Michael Winter M.******@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: delong |
last post by:
Hi
I am trying to display a large image on the form and make the form
scrollable.
My image is about 4200 x 7000 pixel.
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs
e)
{
Graphics g=e.Graphics;
|
by: Vangelis Natsios |
last post by:
I want to create a page with a scrolling image that will cause different
messages to appear on another part of the page (say, another <div>) as the
image will scroll. Imagine something like this:
Image DIV Text DIV
(Visible Area)
+-----------+ Image +---------+...
|
by: Major Man |
last post by:
Hi,
I have this .jpg picture that's 700 x 200. What I wanna do is display
it on a 300 x 200 window, and have it scroll left and right, back and
forth.
Can anyone help this newbie? TIA
|
by: Sharon |
last post by:
I’m wrote a small DLL that used the FreeImage.DLL (that can be found at
http://www.codeproject.com/bitmap/graphicsuite.asp).
I also wrote a small console application in C++ (unmanaged) that uses the
DLL above.
Now the application, together with the above DLL’s is successfully loading a
TIF image file (62992 x 113386 Pixels, Huffman RLE...
|
by: Sam |
last post by:
Hope someone can help...
I have an image on the page which i have made scrollable with the
following code:
<div id="Layer1" style="LEFT: 8px; TOP: 368px; height: 180px;
width:780px; position: absolute; overflow-x: scroll">
<asp:image id="Image1" style="Z-INDEX: 105; LEFT: 8px; TOP:
368px" runat="server"...
| |
by: Andy Baxter |
last post by:
I have an image scrolling in a viewport for a panoramic image
viewer. The viewport can be resized to several set resolutions so people
can adjust the size according to their bandwidth. There are hotspots on
the image which have been defined using an image map. This map is
generated in javascript using the following code (in the object...
|
by: tshad |
last post by:
I am trying to set up an Image authorization where you type in the value
that is in a picture to log on to our site.
I found a program that is supposed to do it, but it doesn't seem to work.
It should put a blue and yellow box on the page with "This is a test" as
part of the picture. But what I get is a broken Gif.
The other problem is...
|
by: Warren Post |
last post by:
At <http://snow.prohosting.com/srcopan/dry/test.es.html>, you will see
that the background image runs down the left margin. The right hand side
of it is faded, watermark style, but it is one single image.
my intention is for the header and text to appear to the right of the
unfaded portion of the image, and on top of the watermarked portion....
|
by: bradyounie |
last post by:
I'm trying to use a Form's BackgroundImage to display the base image that I'm placing controls on top of. To make the form scroll to the bounds of the image, I set the AutoScrollMinSize. This works great, except that when I scroll, the image gets all chopped up and doesn't automatically refresh when scrolling is done.
Is there a way to prevent...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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.
| |
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...
| |