473,714 Members | 2,623 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to create a rotating slide effect in javascript

Hi I am trying to build a roating slide effect in javascript.
Basically, I have a list like below

<ul id="slideShowCn t">
<li id="slide0"><im g .../></li>
<li id="slide0"><im g .../></li>
<li id="slide0"><im g .../></li>
<li id="slide0"><im g .../></li>
<li id="slide0"><im g .../></li>
<li id="slide0"><im g .../></li>
</ul>
<button value="next" />
<button value="prev" />

All the "li" will be placed horizontally (floated using css). At any
given time, only 3 images will be shown. Clicking on the "next/prev"
buttons will slide the images forward and backward. But the images
will have to follow a cyclical path with no end. In other words if you
click on next the first images will slide smoothly to left and the 1st
image will go out of the view. After clicking on the next button a
couple of times the 1st image will cycle back from the right hand
side.
I have implemented the logic for swapping image position but I am
unable to find a way to slide the images smoothly.
can anyone help? I think this has become a little too complicated.

Mar 9 '07 #1
3 5260
On Mar 9, 4:15 am, "Beamer" <amitrai2...@gm ail.comwrote:
Hi I am trying to build a roating slide effect in javascript.
Basically, I have a list like below
All the "li" will be placed horizontally (floated using css). At any
given time, only 3 images will be shown. Clicking on the "next/prev"
buttons will slide the images forward and backward. But the images
will have to follow a cyclical path with no end.
like this-

<html><head><ti tle>Simple doc</title>
<style type="text/css">
li {display:inline ;}
img {width:111;heig ht:77}
ul {position:relat ive;left:0}
</style>
<script type="text/jscript">
function gn(dr){
ulElem=document .getElementById ("slideShowCnt" ).style
effect=setInter val(function(){ ulElem.left=par seInt(ulElem.le ft||0)+
(dr?-1:+1)},1)
setTimeout(func tion(){window.c learInterval(ef fect)},1000)
}
</script>
</head>
<body>
<ul id="slideShowCn t">
<li id="slide0"><im g .../></li>
<li id="slide1"><im g .../></li>
<li id="slide2"><im g .../></li>
<li id="slide3"><im g .../></li>
<li id="slide4"><im g .../></li>
<li id="slide5"><im g .../></li>
</ul>
<button value="next" onclick="gn(1)" />Next</button>
<button value="prev" onclick="gn(0)" />Prev</button>
</body>
</html>

Mar 9 '07 #2
On Mar 9, 6:36 pm, scripts.cont... @gmail.com wrote:
On Mar 9, 4:15 am, "Beamer" <amitrai2...@gm ail.comwrote:
Hi I am trying to build a roating slide effect in javascript.
Basically, I have a list like below
All the "li" will be placed horizontally (floated using css). At any
given time, only 3 images will be shown. Clicking on the "next/prev"
buttons will slide the images forward and backward. But the images
will have to follow a cyclical path with no end.

like this-

<html><head><ti tle>Simple doc</title>
<style type="text/css">
li {display:inline ;}
img {width:111;heig ht:77}
ul {position:relat ive;left:0}
</style>
<script type="text/jscript">
function gn(dr){
ulElem=document .getElementById ("slideShowCnt" ).style
effect=setInter val(function(){ ulElem.left=par seInt(ulElem.le ft||0)+
(dr?-1:+1)},1)
setTimeout(func tion(){window.c learInterval(ef fect)},1000)}

</script>
</head>
<body>
<ul id="slideShowCn t">
<li id="slide0"><im g .../></li>
<li id="slide1"><im g .../></li>
<li id="slide2"><im g .../></li>
<li id="slide3"><im g .../></li>
<li id="slide4"><im g .../></li>
<li id="slide5"><im g .../></li>
</ul>
<button value="next" onclick="gn(1)" />Next</button>
<button value="prev" onclick="gn(0)" />Prev</button>
</body>
</html>
Thats smooth! But I still need to figure out how to make the images
not vanish from the scene!

Mar 10 '07 #3
sc************* @gmail.com wrote:
On Mar 9, 4:15 am, Beamer wrote:
>Hi I am trying to build a roating slide effect in javascript.
Basically, I have a list like below
>All the "li" will be placed horizontally (floated using css).
At any given time, only 3 images will be shown. Clicking on
the "next/prev" buttons will slide the images forward and
backward. But the images will have to follow a cyclical path
with no end.

like this-
* Horizontal layout; yes.
* 3 images show at once; no.
* Clicking buttons slides images in appropriate directions; not reliably.
* Cyclic path; no.
<html><head><ti tle>Simple doc</title>
<style type="text/css">
li {display:inline ;}
img {width:111;heig ht:77}
CSS requires all non-zero dimension values to state the units in which
they are measured. IE may sometimes assume all values without units are
pixel values but other browsers are known to be stricter.
ul {position:relat ive;left:0}
</style>
<script type="text/jscript">
There is nothing in the following code that is unique to JScript(tm) and
so no good reason for using type=text/jscript" and having a number of
browsers regard the type of the script as unsupported.
function gn(dr){
ulElem=document .getElementById ("slideShowCnt" ).style
Why is - ulElem - global when it could be local, and as it is a - style -
object why does its name imply that it is a reference to an element?
effect=setInter val(function(){ ulElem.left=par seInt(ulElem.le ft||0)
Why is - effect - global when it could be local. This one highlights the
reason for never giving a variable more scope than it absolutely needs,
as being global means that a second call to the - gn - function will
re-assign the new value returned from - setInterval - to the one global
variable, meaning that any running - setInterval - will not be terminated
by a subsequent call to - clearInterval -, and the - setTimeout -
scheduled call to - clearInterval - from the preceding use of - gn - will
prematurely stop the setInterval action from the later call to - gn -. If
the - effect - variable were local then at least the inner function used
with setTimeout would be referring to its corresponding - effect -
variable, and cancelling the correct scheduling.

Not that this change would solve the issues with this design, but they
would stop it from being truly chaotic, as it is now.
+ (dr?-1:+1)},1)
Attempting a one millisecond interval is going to flog the browser for no
good reason. Human perception is such that the illusion of continuous
motion is achieved at about 20 frames pre second. Attempting to
re-position anything more often than about 30 frames per second is not
going make anything appear any smoother, and the odds are that the
combination of browser, CPU and OS could not deliver that anyway (with
the OS being a significant impediment).

Also, here the distance travelled is going to be variable. The system is
given a fixed (though imprecise) period in which to make as many one
pixel moves as it can. If the OS is ticking the clock at 10 millisecond
intervals it may get 100 1px steps in, and if at 56 milliseconds it may
manage 17, but both would assume zero time for the execution of the
positioning function and the browser's attempt to re-draw the results.
The actual time taken for these operations will depend on the CPU speed,
the speed of other system components and the loading on the computer
(background tasks and the like), at minimum.
setTimeout(func tion(){window.c learInterval(ef fect)},1000)
}
</script>
</head>
<body>
<ul id="slideShowCn t">
<li id="slide0"><im g .../></li>
^
Why the pseudo xhtml mark-up in a document that appears to be targeted at
IE only (because of the CSS errors and text/jscript script type), given
that IE does not support xhtml?
<li id="slide1"><im g .../></li>
<li id="slide2"><im g .../></li>
<li id="slide3"><im g .../></li>
<li id="slide4"><im g .../></li>
<li id="slide5"><im g .../></li>
</ul>
<button value="next" onclick="gn(1)" />Next</button>
This is where using pseudo xhtml shows itself to be the folly it is. If
this document ever were interpreted as xhtml it would not be well-formed
(which is required of all XML documents), and even if error corrected it
would not be functional, as the <button /tag must be interpreted as a
content-less element, and so potentially have no manifestation on which a
user could click. Certainly clicking on the "Next" text outside the empty
button element would be ineffective.

If a document's viability is predicated upon its only ever being
interpreted as (possibly tag-soup) html (and never xhtml), either because
of the mark-up it contains or its scripted reliance upon the behaviour of
an HTML DOM as opposed to an XHTML DOM, then it doesn't really makes
sense to mark it up as xhtml (or include mark-up resembling xhtml).
<button value="prev" onclick="gn(0)" />Prev</button>
The official default type of a BUTTON element is SUBMIT. IE gets this
wrong and assumes it to be BUTTON, but other browsers will assume SUBMIT
and then interacting with these buttons would submit any form that
contained them. In the absence of a form, as here, there will be no
submission, but still it is advisable to always give a BUTTON element an
explicit TYPE attribute to avoid ambiguities in its default behaviour.
</body>
</html>
What happens here if the user clicks back and forth between buttons (or
repeatedly on the same button) within the second that it takes each
transition to run? At the moment the outcome is chaos, but even with
global variables changed to local variables the outcome is less than
desirable.

Richard.

Mar 10 '07 #4

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

Similar topics

1
4327
by: ajay | last post by:
I have following code for a slide menu but i twiked it to work for a single level menu. Open it in a Browser to get a clear picture. I have 2 Qs 1) How to make first entry as non-link. i.e i want to make first text as Table Heading/menu category. For examle in the given menu i want to make a heading as "Comp. Languages" which won't be a link. 2) The position of this menu is absolute to the page. I want to make it absolute to the Table...
7
3059
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...
14
6557
by: mikeoley | last post by:
Why would this script below work on an html page: http://www.eg-designdev.com/aircylinders/test.htm But not a java page such as this: "http://www.eg-designdev.com/aircylinders/index3.jsp" Or does anybody have a simple slide show rotation script they could refer me to...thanks. <HTML><HEAD>
7
3065
by: Rudy | last post by:
Hello All! After working in the television industry, moving to a developing career has been interesting to say the least. 3 years of developing with books, and the help of you fine folks on this forum, I have learned quite a bit. But that doesn't mean anything when your looking for your first developing gig. 15 years in television production, and not having a college degree in Computer Science does not make me a very good prospect....
2
6545
by: mistral | last post by:
I want place custom text rotating around analogue clock. Here is javascript that is clise to my task: http://javascript.internet.com/time-date/mousetrailclock.html But it have a few unnecessary features which is difficult to alter. i want: 1. replace week/year/days in external circle with my custom text: 'My custom text'
1
2567
by: AR123 | last post by:
Hi I want to set up a rotating banner. Not sure how to incorporate my rotating banner code into the code below. I want the rotating banner to be the main feature image? This is set up in mediasurface My code is: <!-- start page container --> <div id="pageContainer"> <!-- start middle content area --> <div id="genericMiddle">
1
2695
by: Jeigh | last post by:
I've been searching around quite a bit but I can't seem to find what I'm looking for. I'm after a tutorial or source code I could look at for rotating images with a fade effect. I'm looking to have somthing on my site that will rotate a few images (with the fade effect) and have for example the numbers 1, 2, 3, 4, 5 underneath, so clicking on that number would take you to the respective image. I managed to find a few tutorials for this sort of...
7
4401
by: metaphysics | last post by:
For a portfolio I am trying to make, I would like to be able to have a couple thumbnails on the page, that, when clicked, cause a box to horizontally slide in above the thumbnails. I am looking to achieve an effect similar to the one found here: Programming Articles - PHP Scripts, Articles, Tutorials - roScripts, with some minor changes. Instead of arrows to scroll to the next content, I would like thumbnails to trigger the change in...
0
8801
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
8707
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
9174
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
9074
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
9015
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
6634
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
5947
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4725
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2110
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.