JavaScript - Timed Scrolling Function - Need Help
Hello,
I am trying to create an image carousel for the website found here. As you can see everything works fine, however, I would like it to automatically scroll through the images every X seconds. I did not write this script (the credits are still in tact) and I know very very little about writing javascript, so I am hoping someone here can help. Thank you in advance for any replies and any suggestions/tips to making it a better script. The .js file: Code: /** * @author Bruno Bornsztein <bruno@missingmethod.com> * @copyright 2007 Curbly LLC * @package Glider * @license MIT * @url http://www.missingmethod.com/projects/glider/ * @version 0.0.3 * @dependencies prototype.js 1.5.1+, effects.js */ /* Thanks to Andrew Dupont for refactoring help and code cleanup - http://andrewdupont.net/ */ Glider = Class.create(); Object.extend(Object.extend(Glider.prototype, Abstract.prototype), { initialize: function(wrapper, options){ this.scrolling = false; this.wrapper = $(wrapper); this.scroller = this.wrapper.down('div.scroller'); this.sections = this.wrapper.getElementsBySelector('div.section'); this.options = Object.extend({ duration: 1.0, frequency: 3 }, options || {}); this.sections.each( function(section, index) { section._index = index; }); this.events = { click: this.click.bind(this) }; this.addObservers(); if(this.options.initialSection) this.moveTo(this.options.initialSection, this.scroller, { duration:this.options.duration }); // initialSection should be the id of the section you want to show up on load if(this.options.autoGlide) this.start(); }, addObservers: function() { var controls = this.wrapper.getElementsBySelector('div.controls a'); controls.invoke('observe', 'click', this.events.click); }, click: function(event) { this.stop(); var element = Event.findElement(event, 'a'); if (this.scrolling) this.scrolling.cancel(); this.moveTo(element.href.split("#")[1], this.scroller, { duration:this.options.duration }); Event.stop(event); }, moveTo: function(element, container, options){ this.current = $(element); Position.prepare(); var containerOffset = Position.cumulativeOffset(container), elementOffset = Position.cumulativeOffset($(element)); this.scrolling = new Effect.SmoothScroll(container, {duration:options.duration, x:(elementOffset[0]-containerOffset[0]), y:(elementOffset[1]-containerOffset[1])}); return false; }, next: function(){ if (this.current) { var currentIndex = this.current._index; var nextIndex = (this.sections.length - 1 == currentIndex) ? 0 : currentIndex + 1; } else var nextIndex = 1; this.moveTo(this.sections[nextIndex], this.scroller, { duration: this.options.duration }); }, previous: function(){ if (this.current) { var currentIndex = this.current._index; var prevIndex = (currentIndex == 0) ? this.sections.length - 1 : currentIndex - 1; } else var prevIndex = this.sections.length - 1; this.moveTo(this.sections[prevIndex], this.scroller, { duration: this.options.duration }); }, stop: function() { clearTimeout(this.timer); }, start: function() { this.periodicallyUpdate(); }, periodicallyUpdate: function() { if (this.timer != null) { clearTimeout(this.timer); this.next(); } this.timer = setTimeout(this.periodicallyUpdate.bind(this), this.options.frequency*1000); } }); Effect.SmoothScroll = Class.create(); Object.extend(Object.extend(Effect.SmoothScroll.prototype, Effect.Base.prototype), { initialize: function(element) { this.element = $(element); var options = Object.extend({ x: 0, y: 0, mode: 'absolute' } , arguments[1] || {} ); this.start(options); }, setup: function() { if (this.options.continuous && !this.element._ext ) { this.element.cleanWhitespace(); this.element._ext=true; this.element.appendChild(this.element.firstChild); } this.originalLeft=this.element.scrollLeft; this.originalTop=this.element.scrollTop; if(this.options.mode == 'absolute') { this.options.x -= this.originalLeft; this.options.y -= this.originalTop; } }, update: function(position) { this.element.scrollLeft = this.options.x * position + this.originalLeft; this.element.scrollTop = this.options.y * position + this.originalTop; } }); The HTML where inserted onto the page Code: <script type="text/javascript" charset="utf-8">var my_glider = new Glider('my-glider', {duration:0.5});</script> Similar TutorialsI want to be able to display the whole contents of a text file containing 4 paragraphs of text, on a static web page, as soon as a video finishes playing on the page. The video is to be set to autorun as soon as the page loads in the browser. The text file mentioned above, is to remain hidden when the page initially loads and the video is playing. Please I need your advice about what JavaScript code to use to achieve this effect, and where to place the code in the HTML code of the web page. I am new to website design and the use of JavaScript code. I have seen examples of code used for the timed delay of the display of an image file, after a video has finished playing. I do not know how to apply this to the display of a text file. I do not want to convert the whole text file into an image file, as I feel this would negatively affect the search engine optimisation of the page, if there is no text content on the page. Thank you. I need an timed button. When you come to site, you must wait in that site ?? seconds and then button comes pressable.
Hi everyone! I'm new to this forum for posting, but i've been reading threads on this site for a few months now.. seems like a decent place to get info... so, hello everyone! My name's Will, (musical moniker on soundcloud / fb etc is StrangeFlow, i make electronic music, funk, hip hop, etc... ) ..I'm 25, I'm in Lansing , Michigan, my hometown (but still have residency in NorCal, where Im trying to get back to in a few months) I have some experience programming but i'm sure not as much as some of the experts on here i dont know if it's bad etiquette to post a question in my first thread but i have a good question that hasn't been able to get resolved, and I figured someone on here might have some good advice.. Does anyone on here use soundcloud? they have a really nifty timed-comments bar, you can check it out on any soundcloud music page... Ive started seeing it on vimeo recently, I think it's something thats starting to catch on. Anyway,, I had an idea for a website, but the thing is, it would require a timed-comments bar. But.. my problem is, since I'm not as much of an expert as some of the people on here, what would it take to program it? I'm learning some C#, and I heard it would be that or php.. but.. I don't know.. any advice on that timed comments thing? Any good points in the right direction would be extremely appreciated! Thanks everyone! I look forward to posting more in the future on this forum, and I'll gladly offer any of my advice on topics I am knowledgable. -StrangeFlow I once bought some plans on the net and was sent a link that said I could open so many times or for 1 week, I cant remember exactly. But now I am doing a web site and need a link like that any ideas. I would prefer it to open only so many times.
**Solved**
Folks I'm so in the dark about this that I couldn't even think of a sensible title for the thread! One of my colleagues reckons that some years ago she worked on a website that contained images that were set to be visible to users only between certain dates (different dates for different images, so an image representing January would be visible only during January, and so on). Does this sound like something familiar? If so, would it be done using Javascript? Thanks Remster Hello, I am trying to have 4 different images change when the user hits the start button. The speed they change in is based on what selection they have chosen (fast = every second, med = 3 sec, slow = 5 sec), and this cycle repeats until the user has hit the stop button. However, I am struggling to get this to work and have looked around the web for help, but cannot find it. <html> <head> <title>Untitled</title> </head> <body> <img src = "pic1.jpg" id = "swapper"> <form name = "form1"> <input type = "button" value = "Start" onclick = "Swap()"> <input type = "button" value = "Stop" onclick + "Stop()"> Speed: <select name = "Speed"> <option>Slow</option> <option>Medium</option> <option>Fast</option> </select> </form> <script language="JavaScript" type="text/javascript"> var Images = array["pic1.jpg","pic2.jpg","pic3.jpg","pic4.jpg"]; function Swap(){ } function Stop(){ } //clear it: clearInterval(imageSwapInterval); </script> </body> </html> I have not included any attempt of a code for the functions because I have tried at least 8 different things and have failed to get it to properly work each time. Also the array I set up does not work either. Thank you for the help and your time, Crimmm Looks to me like this ought to work, but since I'm here obviously it doesn't. Regarding the HTML in question, there are divs and they do contain child elements. I'm trying to write this in as generic a fashion as possible, without using IDs or other means of targeting elements. And yes, the jQuery library is referenced/linked to the page. Any pointers much appreciated. Thank you <script type="text/javascript"> // <![CDATA[ var x=0; var h=1000; var Divs=document.getElementsByTagName("div"); function fades() { var i=0; var s=0; $("div").fadeOut(1000); while(x<Divs.length) { setInterval('fadeIns()',h); } } function fadeIns() { if(i<100) { Divs[x].childNodes[s].style.opacity=i/100; i++; } else if(s<Divs[x].childNodes.length) { clearInterval(h); s++; i =0; setInterval('fadeIns()',h); } else { clearInterval(h); x++; fades(); } } window.onload=fades; // ]]> </script> First off, i have no idea what to do, because when i get beyond the realm of html/css, vb and php (some) i become lost. I hope someone can help me achieve this because i have no idea what i'm doing, and I've been at it for 2 weeks and no money to hire someone to do this for me. If you ever been in my situation, you know exactly how i feel. I have no code of my own to show you, but hope someone can still help me. I'm have a number 0.0000000, and every min i need that number to increase to 0.0000000, than to 0.0000002 and so on and so forth. Every time i click a button, whatever the number has risen to, it will reset it back down to 0.0000000. Can someone help me out with this? Hi, I've ben trying to figure this one out for days now and so I'd thought to give it a shoot here to see whether anybody can give me any advice or inspiration. Basically what I am trying to do is command a click of a bottom for a certain set time. for example: On the google main search engine page. Once ive typed in a search for "skateboards". I would then like to command the "search" bottom to clicked at 10 pm at night thus executing the search for "skateboards" going into the next page with all the search results. I was wondering if it would be possible to right a Java command that could be run in the Mozilla Fire Fox Scratch pad tool. ( Which is found under Tools --> Web Developer.) Please let me know of anything. It would be very grateful. Thanks, Jon57 Knowing just enough about javascript to get myself in trouble, I have put three timed javascripts to appear from 18 December to the 1 January on three pages of my sister's website. The scripts are on the main index for the site; the index page for the bibliography folder /bibliography/ and in the education folder on just one page: /education/educationlinks.html. Part one of the script inserts the css file; part two of the script inserts a "snowing" script and part three inserts a "make it stop snowing/let it snow" script. Everything is working perfectly for the main index page and the bibliography page. But I cannot figure out why the 3rd "make it stop snowing/let it snow" refuses to show up on the page in the education folder (the snowing javascript IS working on all three pages). There are no errors being thrown and the education page validates. This is the coding for the 3rd script: Code: // snowscript part 3: Show the script between 19-31 Dec and 1 Jan var date = new Date(); var d = date.getDate(); var m = date.getMonth() + 1; dm = d + m; if (m = 12) { if (d > 18) { document.write('<script src="/scripts/snowlinkswitch.js" type="text/javascript" id="snow"></script>'); } else { document.write(''); } } else if (dm == 1,1) { document.write('<script src="/scripts/snowlinkswitch.js" type="text/javascript"></script>'); } else { document.write(''); } This is the coding for snowlinkswitch.js Code: function myhref(){ document.getElementById('myAnchor').innerHTML="please let it snow!"; document.getElementById('myAnchor').href=location.href; document.getElementById('myAnchor').title="let it snow! let it snow!"; document.getElementById('myAnchor').onclick="location.reload(); startstop('spanstyle'); return false;"; } // document.write ('<div id="snowlinks"><img src="/images/snow3aa.gif" width="11" height="11" border="0" alt="*"> <a id="myAnchor" href="" onclick="myhref();hidesnow(); return false;" title="please make it stop snowing!">please make it stop snowing!<\/a> <img src="/images/snow3aa.gif" width="11" height="11" border="0" alt="*"></div> '); I would search for a similar occurrence but have no clue about what search words to use. Does anyone here have an idea about what I have done incorrectly that is causing this to happen? Many thanks. E Morris Toronto, Canada Hi, im fairly new at all this, so please forgive me if I have misunderstood the guidelines on posting threads for this topic. Im needing some help with adding a timed delay for a widget I have on my website. My website is hosted on moonfruit, a flash based web builder, its very beginners level, and so this makes me feel like the new kid at school posting on this forum. however moonfruit does have a HTML/JavaScript snippet Which allows me to paste in code and show the cooliris gallery But is has become crucial to my websites completion that this widget must have a timed delay on it ive been at google for days till the point where im seeing the same pages again, and have come across setTimeout, unfortunately that's as far as I can seem to go, ive tried pasting in the code in numerous places and I just cant get it to work, i have pasted in other JavaScript codes, and they have worked, so i am convinced that its just me being a noob, other than it being a limitation on moonfruit I would appreciate any help with this Here is the code that im trying to get a delayed time of 10 seconds or so. [CODE] <object id="o" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="845" height="350"><param name="movie" value="http://apps.cooliris.com/embed/cooliris.swf"/><param name="allowFullScreen" value="true" /><param name="allowScriptAccess" value="always"/><param name="flashvars" value="style=dark&backgroundColor=#0d0d0d&feed=api://www.flickr.com/?user=41683862@N04%26album=72157622009594203&glowColor=#FFFFFF&showSearch=false&showEmbed=false&show Tutorial=true&showChrome=true"/><embed type="application/x-shockwave-flash" src="http://apps.cooliris.com/embed/cooliris.swf" flashvars="style=dark&backgroundColor=#0d0d0d&feed=api://www.flickr.com/?user=41683862@N04%26album=72157622009594203&glowColor=#FFFFFF&showSearch=false&showEmbed=false&show Tutorial=true&showChrome=true" width="845" height="350" allowFullScreen="true" allowScriptAccess="always"></embed></object> [CODE] Again any help is most appreciated Can someone tell me why this short script won't work? <script type="text/JavaScript"> <!-- function timedRefresh(timeoutPeriod) { var number = rand(7); if (number == 1) { var bgcss = "theme1.css"; } else if (number == 2) { var bgcss = "theme2.css"; } else if (number == 3) { var bgcss = "theme3.css"; } else if (number == 4) { var bgcss = "theme4.css"; } else if (number == 5) { var bgcss = "theme5.css"; } else if (number == 6) { var bgcss = "theme6.css"; } else if (number == 7) { var bgcss = "theme7.css"; } document.write('<link href="bgcss "'+ 'type=text/css rel=stylesheet>'); } // --> </script> </head> <body onload="JavaScript:timedRefresh(10000);"> Hi Guys, I'm embarking on a new project - although I've hit a wall. I require a page to refresh at a scheduled date and time, several times a day. For example, I would like the web page to reload the index at 3:15PM So if anyone has the web page open during that time, it will automatically refresh for them. Timing is quite important so I would need the script to use the server (hosts) time and not the end users time. I am currently deciding on which server language to use, although Javascript is probably a suitable option? or would ajax be more the thing for this? The webpage must execute the refresh at the time 3:15pm, so no matter when someone visits the page, even if its hours before, it must refresh at that time. If anyone has any pointers on the best way to achieve this and what language to start with I am forever greatful I do a lot of image design work and although I have worked with a few coders in the past but I haven't gone too much into coding myself, but its something I'm going to take time to learn and get involved in, so I'm not looking for script hand outs here, mainly just a nudge in the right direction. Thank you guys!! +++ is it possible to scroll / jump to say, 10px above a div? i tried adding padding, but it doesn't work. also, when I use <a href="#xxxx">, is it possible to prevent the browser from adding #xxxx to the url in the browser? thanks!!! +++ Hello. I am in the process of making a basic game board using javascript. Just a table with a bunch of cells that are blank, soon to be colored. However, what I want to do is create my board and be able to scroll depending on where the mouse cursor is. For example, if it is 100px away from the right side of the screen, then move the board to the right. I am trying to use the information from: here I can't seem to get it to work. I have checked firebug, set and checked breakpoints, but it never moves and I am not sure why. Could anyone please help? Thank you. Heres my code: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <style> #land { table-layout: fixed; width: 2500px; height: 2500px; } #land td { width: 25px; height: 25px; border: 1px solid black; empty-cells:show; } #land tr { height: 25px; } </style> <script type="text/javascript" src="World/world.js"></script> <script type="text/javascript" src="mapscrolling.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title></title> </head> <body id="mainBody"> <div id="mainDiv"> </div> <script type="text/javascript" > new CursorDivScroll( 'mainDiv', 20, 20 ); // HERES THE REFERENCE! var i, j; body = document.getElementById("mainDiv"); land = document.createElement("table"); land.setAttribute("id", "land"); land.setAttribute("cellspacing", "0"); land.style.border = "1"; for(i = 0; i < 100; ++i) { var row = document.createElement("tr"); for(j = 0; j < 100; ++j) { var cell = document.createElement("td"); cell.appendChild(document.createElement("div")) // tried &nsbd; but didn't work row.appendChild(cell); } land.appendChild(row); } body.appendChild(land); </script> </body> </html> Hi there, I was wondering of there is any way to have a browser window scroll down when your mouse reaches the bottom of the page? Any help would be much appreciated, Thanks Hi, I'm looking to create a div which contains a list of news items which can be vertically scrolled through by hovering near the top or the bottom of the div. It will then automatically start scrolling through the content. The nearer to the bottom of the div they position their mouse, the faster the scrolling is. Is this something which is possible, and if so how can I do this? Thanks Curt This is what i need to do: I have a single <DIV> </DIV> for rendering dynamic HTML content. it already has a scrollbar in it when it overflows with text. I want to be able to prevent the user from selecting text on the DIV, and at the same time, when they click on the DIV and drag the mouse up or down , the HTML document will be scrolled proportionally to the dragging. i would also like to Hide the Scrollbar (not disable it). any suggestions? I am looking to have a panoramic image used as the background webpage scroll automatically while the page is open. I do not want the user to have to scroll the image or hover over a div. Is there a way to accomplish this in JS?
|