JavaScript - News Slider
Hi. I'm trying to make a news slider for a website in js. This is what I currently have:
Code: <script type="text/javascript"> var refresh = setInterval("refresh()", 5000); function refresh() { $('#top_news').load('top_ten.php').fadeIn("slow"); } </script> The id #top_news is an empty div, in which the news are shown, and the file top_ten.php gets top 10 news from the database, and outputs a random one. The script is working fine, but what I want is, for news to slide in and when a new article slides in, the old one slides out. It would be even better, if there is an excistant script, for news or divs (a small image and text). ALSO, when I refresh/load the site, it takes the time from setInterval, to load the news. Thanks Similar TutorialsI am using a JQuery Slider function in one of my forms that has the folowing code: Code: <script> $(function() { $( "#slider" ).slider({ value:100, min: 0, max: 100, step: 1, slide: function( event, ui ) { $( "#amount" ).val( ui.value + "% Clear" ); } }); $( "#amount" ).val( $( "#slider" ).slider( "value" ) + "% Clear" ); }); </script> And the form looks like: Code: <form method=POST etc...> <div id="slider"></div> <span><input type="text" id="amount" name="Percentage" style="border:0; color:#f6931f; font-weight:bold;" /></span> </form> Now, in the php, I have an error system set up, so that if one of the items in the form are left blank etc., an error will generate without posting the form. However, I am using <?php echo ?> in the form to repopulate the fields that were entered, so user does not have to fill them again. However, the slider always resets back to 100%... How can I fix this so that if the form does not POST, the slider will keep the value that the user set it at. Is this possible, I am having trouble figuring it out. Thanks! Hi ! I would like to have a box in which to loop several html files (every 5 seconds or more) .. or to change the file by pointing buttons at the bottom at the box ... (without making click, just mouseover) I don't know if this is only based on JavaScript .. I don't know if the terms (box .. loop .. html .. buttons) describe exactly what I want to have ... I Googled it for hours .. To be more specific, you could see the well known radio site http://www.wabcradio.com/ and on the left there is Today's Top Stories .. That's what I'm looking for ... I would like to find some site with demos and codes (if possible). Thanks ! PS. I hope I didn't some kind of publicity by putting that link (I'll wipe it out if it's the case .. I've read the rules, and I posted the link because it's not my site and that isn't in any case an advertisement. And I think it is the best way to show what I am asking ... Thanks again ! ) Today, all major cell phone makers (exept apple) announced that they will support a common app standard based on html, css, and javascript. Article: http://news.yahoo.com/s/afp/20100215...owapplications This means that we can use our web skills to make applications for mobile phones. Previously, we would have to invest learning time into a closed-path system like the iPhone's Objective-C, or a minor player's API like webOS. Called BONDI, it's basically a webpage with some extra generic DOM handles for using system features like fetching contact lists, GPS, sending SMSs, playing a sound, etc. While I am not blown away by the demo widgets linked below, i realize they are little more than "hello world", as much actually as figuratively. I expect support and development to entrench around this simple standard, so more and more hardware features will gradually start working on more and more devices. It's the same notion as the JS/HTML software i wrote years ago for firefox that now works in IE8... Check it out: http://bondi.omtp.org/usebondi/Lists...Y/Gallery.aspx I encourage all to participate in developing for open source platforms like BONDI. While there's more money right now in iPhone, the future belongs to us. Don't support proprietary techs! Besides, i cannot imagine that Apple/some fan boy will not eventually add BONDI support to iPhones; they already have a browser! Hi Guys, I am using the following script: Code: <script> JQTWEET = { // Set twitter username, number of tweets & id/class to append tweets user: 'username', numTweets: 3, appendTo: '#shine-tweet-content', // core function of jqtweet loadTweets: function() { $.ajax({ url: 'http://api.twitter.com/1/statuses/user_timeline.json/', type: 'GET', dataType: 'jsonp', data: { screen_name: JQTWEET.user, include_rts: true, count: JQTWEET.numTweets, include_entities: true }, success: function(data, textStatus, xhr) { var html = '<li class="tweet">TWEET_TEXT<div class="time">AGO</div></li>'; // append tweets into page for (var i = 0; i < data.length; i++) { $(JQTWEET.appendTo).append( html.replace('TWEET_TEXT', JQTWEET.ify.clean(data[i].text) ) .replace(/USER/g, data[i].user.screen_name) .replace('AGO', JQTWEET.timeAgo(data[i].created_at) ) .replace(/ID/g, data[i].id_str) ); } } }); }, /** * relative time calculator FROM TWITTER * @param {string} twitter date string returned from Twitter API * @return {string} relative time like "2 minutes ago" */ timeAgo: function(dateString) { var rightNow = new Date(); var then = new Date(dateString); if ($.browser.msie) { // IE can't parse these crazy Ruby dates then = Date.parse(dateString.replace(/( \+)/, ' UTC$1')); } var diff = rightNow - then; var second = 1000, minute = second * 60, hour = minute * 60, day = hour * 24, week = day * 7; if (isNaN(diff) || diff < 0) { return ""; // return blank string if unknown } if (diff < second * 2) { // within 2 seconds return "right now"; } if (diff < minute) { return Math.floor(diff / second) + " seconds ago"; } if (diff < minute * 2) { return "about 1 minute ago"; } if (diff < hour) { return Math.floor(diff / minute) + " minutes ago"; } if (diff < hour * 2) { return "about 1 hour ago"; } if (diff < day) { return Math.floor(diff / hour) + " hours ago"; } if (diff > day && diff < day * 2) { return "yesterday"; } if (diff < day * 365) { return Math.floor(diff / day) + " days ago"; } else { return "over a year ago"; } }, // timeAgo() /** * The Twitalinkahashifyer! * http://www.dustindiaz.com/basement/ify.html * Eg: * ify.clean('your tweet text'); */ ify: { link: function(tweet) { return tweet.replace(/\b(((https*\:\/\/)|www\.)[^\"\']+?)(([!?,.\)]+)?(\s|$))/g, function(link, m1, m2, m3, m4) { var http = m2.match(/w/) ? 'http://' : ''; return '<a class="twtr-hyperlink" target="_blank" href="' + http + m1 + '">' + ((m1.length > 25) ? m1.substr(0, 24) + '...' : m1) + '</a>' + m4; }); }, at: function(tweet) { return tweet.replace(/\B[@?]([a-zA-Z0-9_]{1,20})/g, function(m, username) { return '<a target="_blank" class="twtr-atreply" href="http://twitter.com/intent/user?screen_name=' + username + '">@' + username + '</a>'; }); }, list: function(tweet) { return tweet.replace(/\B[@?]([a-zA-Z0-9_]{1,20}\/\w+)/g, function(m, userlist) { return '<a target="_blank" class="twtr-atreply" href="http://twitter.com/' + userlist + '">@' + userlist + '</a>'; }); }, hash: function(tweet) { return tweet.replace(/(^|\s+)#(\w+)/gi, function(m, before, hash) { return before + '<a target="_blank" class="twtr-hashtag" href="http://twitter.com/search?q=%23' + hash + '">#' + hash + '</a>'; }); }, clean: function(tweet) { return this.hash(this.at(this.list(this.link(tweet)))); } } // ify }; // start jqtweet! JQTWEET.loadTweets(); </script> To load the latest three tweets from a particular twitter account. I am trying to use newsticker.js to only display one at a time, and fade between different the three tweets. However, this is not working, it is working on any normal UL's but not these created using javascript. The page in question is at http://www.garethhardy.com/Shine/ Thanks in advance for any help guys. Dan I'm performing a little maintenance on my news scroller. You can see the scroller on http://www.hogwarts-rpg.net (it's on the right side). Here's the JavaScript: Code: var pos = 300; var scrollTimer; function scroll() { if (!document.getElementById) { return; } var obj = document.getElementById("newsText"); pos -= 1; if (pos < 0 - obj.offsetHeight) { pos = 300; } obj.style.top = pos + "px"; scrollTimer = window.setTimeout(scroll,60); var myNewsText = document.getElementById("newsText"); myNewsText.onmouseover = function(){window.clearTimeout(scrollTimer);} myNewsText.onmouseout = function(){scroll();} } window.onload = scroll; Here's the CSS: Code: /******* NEWS TICKER *******/ #newsBody { width: 200px; height: 300px; color: #000000; font-weight: bold; background-image: url(/images/misc/parchment-scroller-background2.jpg); background-repeat: no-repeat; } /******* LINK COLORS FOR THE TICKER *******/ #newsBody a:link, #newsBody a:visited, #newsBody a:active { text-decoration: underline; color: #000000; } #newsBody a:hover { text-decoration: underline; color: #0000FF; } /******* WHERE THE ACTUAL TEXT APPEARS *******/ #newsWindow { width: 100px; height: 230px; overflow: hidden; position: absolute; top: 200px; left: 50px; } #newsText { width: 100px; position: relative; top: 25px; font-size: x-small; } Basically, I'm trying to make it where it A) resets quicker when it's done with a full scroll-through, and B) where it doesn't scroll up past its containing div (newsWindow in this scenario). I'm sure I'm missing something so simple, but I've been working on it all night without much headway, and I'm exhausted, so there's my excuse. I know that having pos set to reset at 300 might cause a delay in the text showing itself again, but that's to give the effect that it goes "all the way around," if you know what I mean. Even with it not resetting so high, the function still takes longer to reset than I would like it to. Hello, I built a fairly simple page using mioplanet's javascript code for a news ticker. It works fairly well on Chrome, Firefox, Safari and IE7, but IE8 and IE9 can't display it properly. The website is here, and I ran it through w3c validator that pointed out multiple errors with divs nor properly closed (> missing), but on the code they're all there. I suspect the js is doing something funny, but I don't have enough knowledge to understand it. I'm posting the js code as customised by me: Code: TICKER1_CONTENT = document.getElementById("TICKER1").innerHTML; TICKER1_RIGHTTOLEFT = false; TICKER1_SPEED = 5; TICKER1_STYLE = "font-family:inconsolata,courier new, courier, monospace; font-size:24px; color:#ff00cc; letter-spacing:1px"; TICKER1_PAUSED = false; TICKER1_start(); function TICKER1_start() { var tickerSupported = false; TICKER1_WIDTH = document.getElementById("TICKER1").style.width; var img = "<img src=TICKER1_space.gif width="+TICKER1_WIDTH+" height=0>"; // Firefox if (navigator.userAgent.indexOf("Firefox")!=-1 || navigator.userAgent.indexOf("Safari")!=-1) { document.getElementById("TICKER1").innerHTML = "<TABLE cellspacing='0' cellpadding='0' width='100%'><TR><TD nowrap='nowrap'>"+img+"<SPAN style='"+TICKER1_STYLE+"' ID='TICKER1_BODY' width='100%'> </SPAN>"+img+"</TD></TR></TABLE>"; tickerSupported = true; } // IE if (navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Opera")==-1) { document.getElementById("TICKER1").innerHTML = "<DIV nowrap='nowrap' style='width:100%;'>"+img+"<SPAN style='"+TICKER1_STYLE+"' ID='TICKER1_BODY' width='100%'></SPAN>"+img+"</DIV>"; tickerSupported = true; } if(!tickerSupported) document.getElementById("TICKER1").outerHTML = ""; else { document.getElementById("TICKER1").scrollLeft = TICKER1_RIGHTTOLEFT ? document.getElementById("TICKER1").scrollWidth - document.getElementById("TICKER1").offsetWidth : 0; document.getElementById("TICKER1_BODY").innerHTML = TICKER1_CONTENT; document.getElementById("TICKER1").style.display="block"; TICKER1_tick(); } } function TICKER1_tick() { if(!TICKER1_PAUSED) document.getElementById("TICKER1").scrollLeft += TICKER1_SPEED * (TICKER1_RIGHTTOLEFT ? -1 : 1); if(TICKER1_RIGHTTOLEFT && document.getElementById("TICKER1").scrollLeft <= 0) document.getElementById("TICKER1").scrollLeft = document.getElementById("TICKER1").scrollWidth - document.getElementById("TICKER1").offsetWidth; if(!TICKER1_RIGHTTOLEFT && document.getElementById("TICKER1").scrollLeft >= document.getElementById("TICKER1").scrollWidth - document.getElementById("TICKER1").offsetWidth) document.getElementById("TICKER1").scrollLeft = 0; window.setTimeout("TICKER1_tick()", 30); } and this is how it's referred on the html file: Code: <div id=tick1> <div id="TICKER1" STYLE="overflow:hidden; width:1600px"> text here </div> <script type="text/javascript" src="webticker_1.js" language="javascript"></script> any help much appreciated. Thanks, H Hello, i wanna make animated news bar like the one in the top of site alibaba.com, so how can i do that, anybody have any kind of tutorial for any thing like this please ? thanks Hi I'm really new to this and don't really know if I'm in the right place as for posting. I'm trying to figure out if there is a way to have like a news column on each html page that can be updated by making changes to one file. Kinda like a embedded window that gives a sample of some of the text on the highlights page and then has a click to read more. I was thinking a javascript app would be best but I new at this and don't really understand everything. If someone has an idea or can help it'd be appreciated
Hi there, There appears to be some sort of distortion issue with the slider on my client's website. The website is www.tranzaura.com and for some reason some of the slides on the home page appear distorted when viewed in some browsers. See attached image. Can you please check the website on your computer and please let me know if there is distortion. I'd appreciate if you could vote in the poll. Note that there are 9 slides. You can scroll through them if you wish. I have no idea why this is happening. Any thoughts or advice would be appreciated. Thank you ANy programmer can help me to insert this slider script into my website? http://sorgalla.com/projects/jcarous..._vertical.html im using interspire shopping cart. advance thanks I am looking for a slider. Can anybody help me? This is the design of the slider. I use offshore coding service, which failed with superior PSD to WP conversion with basic JS Slider. I know the task is complex, but do not want to hire superficial coders any more. What software can completely replace freelancers to create excellent JS Slider on WordPress engine?
Hey. Right, so I've just paid a guy to design and code just the layout files, not the content, panels, etc. I've coded a panel which will allow my staff to post news articles which will be displayed on the main website. Adding, Editing, Deleting news and all the rest works 100% fine however it appears that the designer has coded the news displayer into a .JS (javascript) file. The news displayer looks like this: ^ This is what it looks like when you hover over one of the 3 news items shown on the right. The image (blue box) changes depending on which news item you hover over This is what it looks like when you then hover over the image for that article: The HTML: Code: <div class="left"> <div id="headline_image_box"> <a href="#"> <img name="imagename" src="_images/_headlines/1.png" alt="Description" /> <span class="desc" id="description"> <script type="text/javascript">writetext(firsttext)</script> </span> </a> </div> </div> <div class="middle"> <a href="#"> <div class="headline" onMouseover="document.imagename.src=image1.src, writeDesc(desc1)" onMouseout="document.imagename.src=image1.src"> <strong>So far so good for Wiggins</strong><br /> Team Sky's Bradley Wiggins says he's going from strength to strength at the Vuelta a Espana. </div> </a> <a href="#"> <div class="headline" onMouseover="document.imagename.src=image2.src, writeDesc(desc2)" onMouseout="document.imagename.src=image2.src"> <strong>Spurs locked in Cahill talks</strong><br /> Bolton Wanderers and Tottenham Hotspur are locked in talks regarding a deal for Gary Cahill. </div> </a> <a href="#"> <div class="headline" onMouseover="document.imagename.src=image3.src, writeDesc(desc3)" onMouseout="document.imagename.src=image3.src"> <strong>Santon set for medical</strong><br /> Italy international Davide Santon has arrived in England to finalise a move to Newcastle United. </div> </a> </div> The Javascript File: Code: if (document.images) { image1 = new Image image2 = new Image image3 = new Image image1.src = "_images/_headlines/1.png" image2.src = "_images/_headlines/2.png" image3.src = "_images/_headlines/3.png" } var desc1='<strong>13th AUG</strong>Description 1' var desc2='<strong>12th AUG</strong>Description 2' var desc3='<strong>11th AUG</strong>Description 3' function writeDesc(what){ document.getElementById('description').innerHTML=''+what+''; } Database Structu Code: CREATE TABLE IF NOT EXISTS `news` ( `id` int(2) NOT NULL AUTO_INCREMENT, `title` varchar(100) NOT NULL, `author` varchar(100) NOT NULL, `category` varchar(100) NOT NULL, `article` varchar(50000) NOT NULL, `image` varchar(500) NOT NULL, `j` varchar(5) NOT NULL, `M` varchar(5) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ; j = Date with letters on end. Eg. 4TH M = 3 character form of month. ALL details submit into database fine, that is not my issue. My issue is that I want to get the latest three articles from the database and echo the values from the database into the javascript however this stuffs up the script completely. I'm not very experienced with using Javascript & PHP together but I noticed something was wrong when I echoed it into the script. Anyone with any ideas/suggestions it'd be very helpful and appreciated! I'd prefer not to have to change to a completely new script, so if you have a way to integrate the MySQL information into the Javascript it'd be great! Hi, im fairly new to coding and need a little bit of help. Does anyone know ho to create a news section like the one on liverpoolfc.tv? Maybe someone knows of a tutorial that could help me or? thanks I started using the Google News Web Element on my website. The website for Google News Web Element is: http://www.google.com/webelements/#!/news I want the links to open in a new window, which cannot be done with the iframe version. Their website only allows me to generate an iframe. I was told that this can be done by using the javascript version, but I have not been able to figure it out. This is their link to the documentation: http://code.google.com/apis/newssearch/newsshow/ I know very little about javascript, and have been trying to get it to work but have been unsuccessful. I want to use the Medium Rectangle size and I want the only topic to be "Swainsboro". The only modification that I want to make is for the links to open in a new window. If anyone can help me do this, it would be appreciated. This is the iframe data that was generated by the wizard: Code: <iframe frameborder=0 marginwidth=0 marginheight=0 border=0 style="border:0;margin:0;width:300px;height:250px;" src="http://www.google.com/uds/modules/elements/newsshow/iframe.html?rsz=large&format=300x250&ned=us&hl=en&q=Swainsboro&element=true" scrolling="no" allowtransparency="true"></iframe> I made a sliding drop down menu and I am having a couple issues. #1) The image that i use as a separator in my nav bar slides down with the slide menu, I would like to try and make that stay in place without sliding with the drop down and sliding back up with the collapse. #2) The very top line in every drop down is not aligning correctly. After the first line the rest of the <li> content below it aligns just fine to the left. Is there something with the very top line of a drop down menu that needs its own styling? Any help is appreciated. I'm trying to make a div slider go left to right. In as much detail this is what I would like: -The div to be hidden on first page load -Have the div slide left to right AND BACK by the click of an image NOT a button -When the image (of a right arrow) is clicked, let the arrow slide out with the div (and IF possible when div is fully extended have image of a left arrow enabling a slide back and vice-versa) Here's what I got so far. (Don't need to use) Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <script type="text/javascript" src="TestSite/js/jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { $('#slideleft button').click(function() { var $lefty = $(this).next(); $lefty.animate({ left: parseInt($lefty.css('left'),10) == 0 ? -$lefty.outerWidth() : 0 }); }); }); </script> <style> .slide { position: relative; overflow: hidden; height: 120px; width: 350px; margin: 1em 0; background-color: #FFF; border: 1px solid #999; } .slide .inner { position: absolute; left: 0; bottom: 0; width: 338px; height: 36px; padding: 6px; background-color: #F00; color: #333; } .slide button { margin: .7em 0 0 .7em; } .js #slidebottom .inner { display: none; } </style> </head> <div id="slideleft" class="slide"> <button><img src="TestSite/js/fancy_nav_right.png" /></button> <div class="inner">Slide from bottom</div> </div> <body> </body> </html> Hi, I cant get the following to work... help would be very much appreciated, thank you. I also have it uploaded on pagemaster.co.za/_test/ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta charset="utf-8"> <title>Test Slider</title> <link href="test.css" rel="stylesheet" type="text/css" media="screen" /> </head> <body onLoad="slideA()"> <div id="container"> <img src="images/img1.jpg" id="imgslide" /> <div id="left_holder"><img onClick="slide(-1)" class="left" src="images/arrow-left.png" /></div> <div id="right_holder"><img onClick="slide(1)" class="right" src="images/arrow-right.png" /></div> </div> <script type="text/javascript" src="test.js"></script> </body> </html> #container { height: 360px; width: 960px; margin: 20px auto; position: relative } #imgslide { height: 360px; width: 960px; position: absolute } #left_holder { height: 360px; width: 100px; position: absolute; left: 0px; top: 0px; } #right_holder { height: 360px; width: 100px; position: absolute; right: 0px; top: 0px; } .left { height: 48px; width: 48px; position: absolute; top: 40%; left: 0px; } .right { height: 48px; width: 48px; position: absolute; top: 40%; right: 0px; } and the js... var imagecount = 1; var total = 8; function slide(x) { "use strict"; var Image = document.getElementById('img'); imagecount = imagecount + x; if (imagecount > total) { imagecount = 1; } if (imagecount < 1) { imagecount = total; } Image.src = "images/img" + imagecount + ".jpg"; } window.setInterval(function slideA() { "use strict"; var Image = document.getElementById('img'); imagecount = imagecount + 1; if (imagecount > total) { imagecount = 1; } if (imagecount < 1) { imagecount = total; } Image.src = "images/img" + imagecount + ".jpg"; }, 5000); I have a question, How do you create a slider for a website? I am not familiar with anything but html and css, but I would like to create a simple image slider for my site. How would I go about doing that? Any help is appreciated Thanks if you look on my website here you will see a slider on the front page. works fine on all browsers except for internet explorer. on IE, when each picture scrolls, the page will scroll itself down to the bottom. also, after about 4 pictures are scrolled, the slider stops and is just a white box for the rest of the time. does anyone have any ideas??? thanks (if you check the validator it says something about not understanding the value "allowTransparency") thanks again! |