JavaScript - Modifying The Functionality On A Border-fading Script
Hi all,
I have been using a border-fading script to give the impression of onmouseover fading underline, and I wish to tweak it a bit to give a slightly different effect I have two scripts that do virtually the same thing, although the second has a display bug in FF both have their advantages and I don't have my heart set on using either one, although Vic's scripts are being used all over the page i'm creating so his has first dibs here they are, and I will describe what I need to do below: first script: Code: startColor = "FFFFFF"; // MouseOut link color endColor = "000000"; // MouseOver link color stepIn = 20; // delay when fading in stepOut = 30; // delay when fading out var fading=new Array(); fading['now']=startColor; function initLinkFade() { var links = document.getElementById('pageHolder').getElementsByTagName('A'); for(var i=0;i<links.length;i++){ links[i].onmouseover = domouseover; links[i].onmouseout = domouseout; } } if(document.getElementsByTagName){ window.onload = initLinkFade; document.write("<style type='text/css'>#pageHolder a{text-decoration:none}</style>"); } function domouseover() { var rel="nofollow" target=arguments[0]?arguments[0].target:event.srcElement; if(target.nodeName!='A')return; for(var i=0;i<fading.length;i++) clearTimeout(fading[i]); if(fading['el']!=target && fading['el']){ fading['el'].style.borderBottom = "1px solid #"+startColor; linkFade(startColor,endColor,target,stepIn); } else linkFade(fading['now'],endColor,target,stepIn); } function domouseout() { var rel="nofollow" target=arguments[0]?arguments[0].target:event.srcElement; if(target.nodeName!='A')return; for(var i=0;i<fading.length;i++) clearTimeout(fading[i]); if(fading['el']!=target && fading['el']){ fading['el'].style.borderBottom = "1px solid #"+startColor; linkFade(endColor,startColor,target,stepOut); } else linkFade(fading['now'],startColor,target,stepOut); } function hex(i) { var s=Math.floor(i).toString(16); return s.length==2?s:"0"+s; } function linkFade(s,e,element,step){ fading['el']=element; var sr=parseInt(s.substr(0,2),16); var sg=parseInt(s.substr(2,2),16); var sb=parseInt(s.substr(4,2),16); var er=parseInt(e.substr(0,2),16); var eg=parseInt(e.substr(2,2),16); var eb=parseInt(e.substr(4,2),16); for(var i = 0; i <= step; i++) { var r=hex((sr*(step-i)+er*i)/step); var g=hex((sg*(step-i)+eg*i)/step); var b=hex((sb*(step-i)+eb*i)/step); fading[i]=setTimeout("fading['now']='"+r+g+b+"';fading['el'].style.borderBottom = '1px solid #'+fading['now']",i*step); } } What I like about this one is that you can specify both the fade in and fade out speeds, allowing you a bunch of flexibility in how it looks also, I like how it allows you to set it to 'apply to all links in a given div... however that can have certain downfalls you can seethis script in action he www.enviromark.ca/head/YPP.htm the second script Code: <!-- // by Vic Phillips (04-September-2006) http://www.vicsjavascripts.org.uk function zxcMseOver(zxcobj,zxcd){ var zxcp=zxcobj; if (!zxcp.oop){ return; } clearTimeout(zxcp.oop.to); zxcp.oop.d=zxcd||0; zxcp.oop.cng(); } function zxcInit(zxccls,zxccol1,zxccol2,zxcstps){ var zxclks=document.getElementsByTagName('BODY')[0].getElementsByTagName('A'); for (var zxc0=0;zxc0<zxclks.length;zxc0++){ if (zxclks[zxc0].className==zxccls){ zxcStyle(zxclks[zxc0],{borderBottom:'solid '+zxccol1+' 0px;'}); zxclks[zxc0].oop=new zxcOOP(zxclks[zxc0],zxccol1,zxccol2,zxcstps); } } } var zxcCnt=0; function zxcOOP(zxcd,zxccol1,zxccol2,zxcstps){ this.obj=zxcd; this.ary=zxcSTxtColors([zxccol1,zxccol2],zxcstps||10); this.cnt=0; this.d=1 this.to=null; this.ref='zxcoop'+zxcCnt; window[this.ref]=this; zxcCnt++; } zxcOOP.prototype.cng=function(){ if ((this.d>0&&this.cnt<this.ary.length-1)||(this.d<0&&this.cnt>0)){ this.obj.style.borderBottom='solid #'+this.ary[this.cnt+=this.d]+' 1px'; this.setTimeOut("cng();",100); } else if (this.d<0) { this.obj.style.borderBottom='0px'; } } zxcOOP.prototype.setTimeOut=function(zxcf,zxcd){ this.obj.to=setTimeout("window."+this.ref+"."+zxcf,zxcd); } function zxcStyle(zxcele,zxcstyle){ if (typeof(zxcele)=='string'){ zxcele=document.createElement(zxcele); } for (key in zxcstyle){ zxcele.style[key]=zxcstyle[key]; } return zxcele; } function zxcSTxtColors(zxcc,zxcnu){ var zxcary=[]; zxcc1=zxcc[0].replace('#',''); zxcc2=zxcc[1].replace('#',''); var zxcr=zxcHexToInt(zxcc1.substring(0,2)); var zxcg=zxcHexToInt(zxcc1.substring(2,4)); var zxcb=zxcHexToInt(zxcc1.substring(4,6)); var zxcr2=zxcHexToInt(zxcc2.substring(0,2)); var zxcg2=zxcHexToInt(zxcc2.substring(2,4)); var zxcb2=zxcHexToInt(zxcc2.substring(4,6)); var zxcrstep=Math.round((zxcr2-zxcr)/zxcnu); var zxcgstep=Math.round((zxcg2-zxcg)/zxcnu); var zxcbstep=Math.round((zxcb2-zxcb)/zxcnu); for (zxc0=0;zxc0<zxcnu;zxc0++){ zxcary[zxc0]=zxcIntToHex(zxcr)+zxcIntToHex(zxcg)+zxcIntToHex(zxcb); zxcr+=zxcrstep; zxcg+=zxcgstep; zxcb+=zxcbstep; } zxcary[zxcnu-1]=zxcc[1].substring(1); return zxcary; } function zxcIntToHex(zxcn){ zxcn=(zxcn>255)?255:(zxcn<0)?0:zxcn; var zxcresult=zxcn.toString(16); if (zxcresult.length==1){ zxcresult="0"+zxcresult; } return zxcresult; } function zxcHexToInt(zxchex){ return parseInt(zxchex,16); } //--> activated by: <body onload="zxcInit('mainLinks','#FFFFFF','#000000',15);"> ... <a class="mainLinks" href="#advantagesRisks" onmouseover="zxcMseOver(this,1);" onmouseout="zxcMseOver(this,-1);"><img src="images/EN_advantages_risks.gif" name="imageLinkNoTouchy"></a> I like this script because it allows you to set the fade on a per-link basis, not on a per-div basis... more control alrighty, here are the minor modifications I am hoping to get help with The fade-out effects stop when a second link is onmouseover'd. I would like to be able to set both the fade-in and fade-out delays (like in the first script), but have the fade-out continue for "Link A" even if "Link B" is onmouse'd over. Basically getting the smooth-fade effect seen he www.enviromark.ca/head/ --> the gray icons. When a link is clicked, I would like the top border of the link to fade in and stay solid until another link is clicked. When another link is clicked, I would like it's top border to fade in (like the first link) a have the first link's top border fade out. Again you can see the effect I'm going for at the link above by clicking on a few of the vertical links and seeing it's effect on the horizontal images I know this might be a lot to ask, so I suppose I could live with the script I have... but I figured there was no harm in asking Similar TutorialsI am trying to modify a popup script to popup a lightbox on page load instead of a new window. The script identifies if the user is a new visitor and displays the popup only to new visitors. Typically, the lightbox is triggered by an a:link. I would like to trigger it using this script so that the lightbox pops up automatically for new visitors only. Here is the popup script: Code: <SCRIPT LANGUAGE="JavaScript"> <!-- function GetCookie(name) { var arg=name+"="; var alen=arg.length; var clen=document.cookie.length; var i=0; while (i<clen) { var j=i+alen; if (document.cookie.substring(i,j)==arg) return "here"; i=document.cookie.indexOf(" ",i)+1; if (i==0) break; } return null; } var visit=GetCookie("COOKIE1"); if (visit==null){ var expire=new Date(); window.name = "thiswin"; newwin=open("http://www.pccmedia.net/P25_60sec.php", "dispwin", "width=350,height=350,scrollbars=yes,menubar=no"); expire=new Date(expire.getTime()+7776000000); document.cookie="COOKIE1=here; expires="+expire; } // --> </SCRIPT> I want to replace the newwin=open... command with something that will trigger the lightbox. The section of the lightbox script that receives the trigger and variables is.... Code: Mediabox.scanPage = function() { // $$('#mb_').each(function(hide) { hide.set('display', 'none'); }); var links = $$("a").filter(function(el) { return el.rel && el.rel.test(/^lightbox/i); }); $$(links).mediabox({/* Put custom options here */}, null, function(el) { var rel0 = this.rel.replace(/[[]|]/gi," "); var relsize = rel0.split(" "); return (this == el) || ((this.rel.length > 8) && el.rel.match(relsize[1])); }); }; window.addEvent("domready", Mediabox.scanPage); An example of the typical HTML tag that triggers the lightbox and feeds the variables is Code: <a href="http://www.pccmedia.net/other/P25_60sec.mp4" rel="lightbox[set 720 405]" title="Project 25" onClick="stop1()"/> The rel=lightbox... is the trigger for the lightbox. The stop1() function refers to a separate script that plays background music on the website. This also needs to be included in the new visitor popup script, but is a separate issue..... I'm not familiar enough with JS to be able to figure this out. Any help would be GREATLY appreciated. Hi, I want to take this redirect script and modify it so that it rotates a banner image instead of sending the user to another page. The script works so that if the window is out of focus for 10 seconds, it redirects. The images are defined in an external style sheet so I guess I'll have to move that into the document. Also, I want it to be able to work more than once with multiple images, like if the user opens a new tab, comes back, goes to a different tab, the image should change twice. Here's the script: Code: <script type="text/javascript"> var xScroll, yScroll, timerPoll, timerRedirect, timerClock; function initRedirect(){ if (typeof document.body.scrollTop != "undefined"){ //IE,NS7,Moz xScroll = document.body.scrollLeft; yScroll = document.body.scrollTop; clearInterval(timerPoll); //stop polling scroll move clearInterval(timerRedirect); //stop timed redirect timerPoll = setInterval("pollActivity()",1); //poll scrolling timerRedirect = setInterval("location.href='http://www.google.com",10000); //set timed redirect } else if (typeof window.pageYOffset != "undefined"){ //other browsers that support pageYOffset/pageXOffset instead xScroll = window.pageXOffset; yScroll = window.pageYOffset; clearInterval(timerPoll); //stop polling scroll move clearInterval(timerRedirect); //stop timed redirect timerPoll = setInterval("pollActivity()",1); //poll scrolling timerRedirect = setInterval("location.href='http://www.google.com'",10000); //set timed redirect } //else do nothing } function pollActivity(){ if ((typeof document.body.scrollTop != "undefined" && (xScroll!=document.body.scrollLeft || yScroll!=document.body.scrollTop)) //IE/NS7/Moz || (typeof window.pageYOffset != "undefined" && (xScroll!=window.pageXOffset || yScroll!=window.pageYOffset))) { //other browsers initRedirect(); //reset polling scroll position } } document.onmousemove=initRedirect; document.onclick=initRedirect; document.onkeydown=initRedirect; window.onload=initRedirect; window.onresize=initRedirect; </script> The image is defined in Code: <div id="home" style="background: url(images/banner.png) no-repeat;"></div> I'm thinking I should replace banner.png with a variable or array name that has the image names defined somewhere and using a loop to choose the next image in the array. I took a C++ class but I don't know any JS, sorry for not doing homework. Thanks for reading this Hi all, I found a small fading script online which suits my needs though I need some help changing it around a bit as it seems to only work once in a page (i.e. a second occurance of the code doesn't work though the first one continues). Also, I'm not quite sure how to put it into a .js external page and then call the specific function as many times as I want in the body and have it all work. Please advise on this issue (i.e. Putting the code in an external file and then calling the fadeIn() function as many times as I want in the body). Thanks. BTW, the concept is a fixed imaged with the js fading another image over the top of that first image in and out over and over again. All the images and application of the js will be the same for all occurrences on the page (don't know if that's relevant to the solution I'm asking for but throwing it in there just in case). Here is the code: Code: <html> <body style="background:#000;"> <div style="float:left;"> <img style="float:left;" id="me" src="fade_arrow2.png"/> <img style="float:left;margin-left:-44px;" src="fade_arrow1.png"/> <script type="text/javascript"> var element = document.getElementById('me') ; var duration = 4000; /* 1000 millisecond fade = 1 sec */ var steps = 20; /* number of opacity intervals */ var delay = 5000; /* 5 sec delay before fading out */ /* set the opacity of the element (between 0.0 and 1.0) */ function setOpacity(level) { element.style.opacity = level; element.style.MozOpacity = level; element.style.KhtmlOpacity = level; element.style.filter = "alpha(opacity=" + (level * 100) + ");"; } function fadeIn(){ for (i = 0; i <= 1; i += (1 / steps)) { setTimeout("setOpacity(" + i + ")", i * duration); } setTimeout("fadeOut()", delay); } function fadeOut() { for (i = 0; i <= 1; i += (1 / steps)) { setTimeout("setOpacity(" + (1 - i) + ")", i * duration); } setTimeout("fadeIn()", duration); } /* start the effect */ fadeIn(); </script> </div> </body> </html> Hi, I am using this image rotation tool on my website but I would like to alter it slightly http://www.zurb.com/playground/orbit...y-image-slider See the small navigation dots under the images to select individual pages there are 4 of them (more if you add more images) - on 1 horizontal line. I would like to alter the code if possible so that the dots are in pairs going down the page (I wont bore you with the reason why) ie: o o o o o o o o etc The code the handles the dots is this: Code: // ================== // ! BULLET NAV // ================== //Bullet Nav Setup if(options.bullets) { var bulletHTML = '<ul class="orbit-bullets"></ul>'; orbitWrapper.append(bulletHTML); var bullets = orbitWrapper.children('ul.orbit-bullets'); for(i=0; i<numberSlides; i++) { var liMarkup = $('<li>'+(i+1)+'</li>'); if(options.bulletThumbs) { var thumbName = slides.eq(i).data('thumb'); if(thumbName) { var liMarkup = $('<li class="has-thumb">'+i+'</li>') liMarkup.css({"background" : "url("+options.bulletThumbLocation+thumbName+") no-repeat"}); } } orbitWrapper.children('ul.orbit-bullets').append(liMarkup); liMarkup.data('index',i); liMarkup.click(function() { stopClock(); shift($(this).data('index')); }); } setActiveBullet(); } //Bullet Nav Execution function setActiveBullet() { if(!options.bullets) { return false; } else { bullets.children('li').removeClass('active').eq(activeSlide).addClass('active'); } } The CSS for this is: Code: /* BULLET NAV ================================================== */ .orbit-bullets { position: absolute; z-index: 1000; list-style: none; bottom: 150px; left: 0%; margin-left: 0px; padding: 0; } .orbit-bullets li { float: left; margin-left: 5px; cursor: pointer; color: #999; text-indent: -9999px; background: url(bullets.png) no-repeat 4px 0; width: 13px; height: 12px; overflow: hidden; } .orbit-bullets li.active { color: #222; background-position: -8px 0; } .orbit-bullets li.has-thumb { background: none; width: 100px; height: 75px; } .orbit-bullets li.active.has-thumb { background-position: 0 0; border-top: 2px solid #000; } The image file for the small dots is this: I'm afraid I'm not a Java person at all and know little about it so I would be very grateful if you could help me out with it... if it's possible. Thanks. PP. Here is the style and js for my menu that I got from Dynamic Drive. I have it working as it is suppose to on my site. But I need my menus to have submenus and even have a couple of sub-submenus. Can someone help me with this. Code: YOffset=150; // no quotes!! XOffset=0; staticYOffset=30; // no quotes!! slideSpeed=20 // no quotes!! waitTime=100; // no quotes!! this sets the time the menu stays out for after the mouse goes off it. menuBGColor="black"; menuIsStatic="yes"; //this sets whether menu should stay static on the screen menuWidth=180; // Must be a multiple of 10! no quotes!! menuCols=2; hdrFontFamily="verdana"; hdrFontSize="2"; hdrFontColor="white"; hdrBGColor="#170088"; hdrAlign="left"; hdrVAlign="center"; hdrHeight="15"; linkFontFamily="Verdana"; linkFontSize="2"; linkBGColor="white"; linkOverBGColor="#FFFF99"; linkTarget="_top"; linkAlign="Left"; barBGColor="#FF0000"; barFontFamily="Verdana"; barFontSize="3"; barFontColor="white"; barVAlign="center"; barWidth=45; // no quotes!! barText="Menu Navigation"; // <IMG> tag supported. Put exact html for an image to show. /////////////////////////// // ssmItems[...]=[name, link, target, colspan, endrow?] - leave 'link' and 'target' blank to make a header ssmItems[0]=["Menu"] //create header ssmItems[1]=["About Our Diocese", "http://www.ptdiocese.org/about-us/about-us.shtml, ""] ssmItems[2]=["Parishes", "http://www.ptdiocese.org/parishes/parish.shtml",""] ssmItems[3]=["Schools", "http://www.ptdiocese.org/schools/schools.shtml", ""] ssmItems[4]=["Ministries", "http://www.ptdiocese.org/christian-formation/christian-formation.shtml", "_new"] ssmItems[5]=["Clergy and Religous", "http://www.ptdiocese.org/clergy-religious/clergy-religious.shtml", ""] ssmItems[6]=["Protecting God's Children", "http://www.ptdiocese.org/protecting-children/protecting-children.shtml", ""] ssmItems[7]=["For Those In Need", "http://www.ptdiocese.org/in-need/in-need.shtml", ""] ssmItems[8]=["Tribunal", "http://www.ptdiocese.org/tribunal/tribunal.shtml", ""] ssmItems[9]=["Contact Us"] //ssmItems[7]=["Tribunal", "http://www.ptdiocese.org", "", 1, "no"] //create two column row //ssmItems[8]=["Contact Us", "http://www.ptdiocese.org", "",1] ssmItems[10]=["External Links", "", ""] //create header ssmItems[11]=["Test", "http://www.javascriptkit.com", ""] ssmItems[12]=["Test", "http://www.freewarejava.com", ""] ssmItems[13]=["Test", "http://www.codingforums.com", ""] buildMenu(); //--> NS6 = (document.getElementById&&!document.all) IE = (document.all) NS = (navigator.appName=="Netscape" && navigator.appVersion.charAt(0)=="4") tempBar='';barBuilt=0;ssmItems=new Array(); function truebody(){ return (document.compatMode!="BackCompat")? document.documentElement : document.body } moving=setTimeout('null',1) function moveOut() { if ((NS6||NS)&&parseInt(ssm.left)<0 || IE && ssm.pixelLeft<0) { clearTimeout(moving);moving = setTimeout('moveOut()', slideSpeed);slideMenu(10)} else {clearTimeout(moving);moving=setTimeout('null',1)}}; function moveBack() {clearTimeout(moving);moving = setTimeout('moveBack1()', waitTime)} function moveBack1() { if ((NS6||NS) && parseInt(ssm.left)>(-menuWidth) || IE && ssm.pixelLeft>(-menuWidth)) { clearTimeout(moving);moving = setTimeout('moveBack1()', slideSpeed);slideMenu(-10)} else {clearTimeout(moving);moving=setTimeout('null',1)}} function slideMenu(num){ if (IE) {ssm.pixelLeft += num;} if (NS6) {ssm.left = parseInt(ssm.left)+num+"px";} if (NS) {ssm.left = parseInt(ssm.left)+num; bssm.clip.right+=num;bssm2.clip.right+=num;}} function makeStatic() { if (NS||NS6) {winY = window.pageYOffset;} if (IE) {winY = truebody().scrollTop;} if (NS6||IE||NS) { if (winY!=lastY&&winY>YOffset-staticYOffset) { smooth = .2 * (winY - lastY - YOffset + staticYOffset);} else if (YOffset-staticYOffset+lastY>YOffset-staticYOffset) { smooth = .2 * (winY - lastY - (YOffset-(YOffset-winY)));} else {smooth=0} if(smooth > 0) smooth = Math.ceil(smooth); else smooth = Math.floor(smooth); if (IE) bssm.pixelTop+=smooth; if (NS6) bssm.top=parseInt(bssm.top)+smooth+"px" if (NS) bssm.top=parseInt(bssm.top)+smooth lastY = lastY+smooth; setTimeout('makeStatic()', 1)}} function buildBar() { if(barText.indexOf('<IMG')>-1) {tempBar=barText} else{for (b=0;b<barText.length;b++) {tempBar+=barText.charAt(b)+"<BR>"}} document.write('<td align="center" rowspan="100" width="'+barWidth+'" bgcolor="'+barBGColor+'" valign="'+barVAlign+'"><p align="center"><font face="'+barFontFamily+'" Size="'+barFontSize+'" COLOR="'+barFontColor+'"><B>'+tempBar+'</B></font></p></TD>')} function initSlide() { if (NS6){ssm=document.getElementById("thessm").style;bssm=document.getElementById("basessm").style; bssm.clip="rect(0 "+document.getElementById("thessm").offsetWidth+" "+document.getElementById("thessm").offsetHeight+" 0)";ssm.visibility="visible";} else if (IE) {ssm=document.all("thessm").style;bssm=document.all("basessm").style bssm.visibility = "visible";} else if (NS) {bssm=document.layers["basessm1"]; bssm2=bssm.document.layers["basessm2"];ssm=bssm2.document.layers["thessm"]; bssm2.clip.left=0;ssm.visibility = "show";} if (menuIsStatic=="yes") makeStatic();} function buildMenu() { if (IE||NS6) {document.write('<DIV ID="basessm" style="visibility:hidden;Position : Absolute ;Left : '+XOffset+'px ;Top : '+YOffset+'px ;Z-Index : 20;width:'+(menuWidth+barWidth+10)+'px"><DIV ID="thessm" style="Position : Absolute ;Left : '+(-menuWidth)+'px ;Top : 0 ;Z-Index : 20;" onmouseover="moveOut()" onmouseout="moveBack()">')} if (NS) {document.write('<LAYER name="basessm1" top="'+YOffset+'" LEFT='+XOffset+' visibility="show"><ILAYER name="basessm2"><LAYER visibility="hide" name="thessm" bgcolor="'+menuBGColor+'" left="'+(-menuWidth)+'" onmouseover="moveOut()" onmouseout="moveBack()">')} if (NS6){document.write('<table border="0" cellpadding="0" cellspacing="0" width="'+(menuWidth+barWidth+2)+'px" bgcolor="'+menuBGColor+'"><TR><TD>')} document.write('<table border="0" cellpadding="0" cellspacing="1" width="'+(menuWidth+barWidth+2)+'px" bgcolor="'+menuBGColor+'">'); for(i=0;i<ssmItems.length;i++) { if(!ssmItems[i][3]){ssmItems[i][3]=menuCols;ssmItems[i][5]=menuWidth-1} else if(ssmItems[i][3]!=menuCols)ssmItems[i][5]=Math.round(menuWidth*(ssmItems[i][3]/menuCols)-1); if(ssmItems[i-1]&&ssmItems[i-1][4]!="no"){document.write('<TR>')} if(!ssmItems[i][1]){ document.write('<td bgcolor="'+hdrBGColor+'" HEIGHT="'+hdrHeight+'px" ALIGN="'+hdrAlign+'" VALIGN="'+hdrVAlign+'" WIDTH="'+ssmItems[i][5]+'" COLSPAN="'+ssmItems[i][3]+'"> <font face="'+hdrFontFamily+'" Size="'+hdrFontSize+'" COLOR="'+hdrFontColor+'"><b>'+ssmItems[i][0]+'</b></font></td>')} else {if(!ssmItems[i][2])ssmItems[i][2]=linkTarget; document.write('<TD BGCOLOR="'+linkBGColor+'" onmouseover="bgColor=\''+linkOverBGColor+'\'" onmouseout="bgColor=\''+linkBGColor+'\'" WIDTH="'+ssmItems[i][5]+'px" COLSPAN="'+ssmItems[i][3]+'"><ILAYER><LAYER onmouseover="bgColor=\''+linkOverBGColor+'\'" onmouseout="bgColor=\''+linkBGColor+'\'" WIDTH="100%" ALIGN="'+linkAlign+'"><DIV ALIGN="'+linkAlign+'"><FONT face="'+linkFontFamily+'" Size="'+linkFontSize+'"> <A HREF="'+ssmItems[i][1]+'" target="'+ssmItems[i][2]+'" CLASS="ssmItems">'+ssmItems[i][0]+'</DIV></LAYER></ILAYER></TD>')} if(ssmItems[i][4]!="no"&&barBuilt==0){buildBar();barBuilt=1} if(ssmItems[i][4]!="no"){document.write('</TR>')}} document.write('</table>') if (NS6){document.write('</TD></TR></TABLE>')} if (IE||NS6) {document.write('</DIV></DIV>')} if (NS) {document.write('</LAYER></ILAYER></LAYER>')} theleft=-menuWidth;lastY=0;setTimeout('initSlide();', 1)} Hello, I have a script that makes a link a different color on click, i would like to add a hover color to the links that are NOT active. Script below. Thanks in advance! Code: function activate(el) { var links=document.getElementsByTagName("a"); for(i=0;i<links.length;i++) { if(links[i].className=="toggle") { links[i].style.color="#999"; } } el.style.color="#DF8700"; } Hi everyone, I have a countdown script I'd like to modify so that the countdown ends at a specific hour, and not on a particular day at midnight. I'm new to coding (Ruby), so still trying to get the hang of Javascript: Code: var current="Expired" var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") function countdown(yr,m,d){ theyear=yr;themonth=m;theday=d var today=new Date() var todayy=today.getYear() if (todayy < 1000) todayy+=1900 var todaym=today.getMonth() var todayd=today.getDate() var todayh=today.getHours() var todaymin=today.getMinutes() var todaysec=today.getSeconds() var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec futurestring=montharray[m-1]+" "+d+", "+yr dd=Date.parse(futurestring)-Date.parse(todaystring) dday=Math.floor(dd/(60*60*1000*24)*1) dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1) dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1) dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1) if(dday==0&&dhour==0&&dmin==0&&dsec==1){ document.getElementById('counter').style.display='none'; document.getElementById('expired').style.display='block'; return } else{ document.getElementById('countdown_day').innerHTML=dday; document.getElementById('countdown_hour').innerHTML=dhour; document.getElementById('countdown_min').innerHTML=dmin; document.getElementById('countdown_sec').innerHTML=dsec; setTimeout("countdown(theyear,themonth,theday)",1000) } } //MODIFY THIS LINE: enter the count down date using the format year/month/day //e.g. countdown(2009, 03, 23); countdown(2011, 12, 24); I've tried to play with it by changing the following in green: Code: function countdown(yr,m,d, h ){ theyear=yr;themonth=m;theday=d; thehour=h . . . setTimeout("countdown(theyear,themonth,theday, thehour )",1000) . . countdown(2011, 12, 24, 10 ) But I don't seem to be getting anywhere. Any tips or pointers to push me in the right direction is much appreciated. Thanks! Hello Everyone, I am in the process of creating a billboard script for our company front page which will switch between two images. I am using the following script as a base: http://tympanus.net/codrops/2009/12/...query-and-css/ I am eager to learn coding, but am still a novice at it so I was wondering if anyone could assist me with adding the following functionality: 1. Rather than (or perhaps in addition to) having the two images change based on a timer, I'd like to be able to insert a "next" arrow. Therefore I will need assistance in coding a button to change the images from "ad_1" to "ad_2" which is currently done automatically by the interval timer 2. I'd like to make the images clickable with unique destinations (so when you click on "ad_1" it will take you to "link 1", "ad_2" will take you to "link 2" Below is my current code: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <title>Rotating Billboard with jQuery</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> <link rel="stylesheet" href="css/style.css" type="text/css" charset="utf-8"/> </head> <body> <div class="palmtrees"></div> <div class="powerline"></div> <div class="city"></div> <div class="container"> <div class="ad"> <div id="ad_1" class="ad_1"> <img class="slice_1" src="ads/ad1_slice01.jpg"/> <img class="slice_2" src="ads/ad1_slice02.jpg"/> <img class="slice_3" src="ads/ad1_slice03.jpg"/> </div> <div id="ad_2" class="ad_2"> <img class="slice_1" src="ads/ad2_slice01.jpg"/> <img class="slice_2" src="ads/ad2_slice02.jpg"/> <img class="slice_3" src="ads/ad2_slice03.jpg"/> </div> </div> </div> <div class="billboard"></div> <a class="back" href="http://tympanus.net/codrops/2009/12/16/creating-a-rotating-billboard-system-with-jquery-and-css/"><a> <script src="jquery-1.3.2.js" type="text/javascript"></script> <script> $(function() { $('#ad_1 > img').each(function(i,e){ rotate($(this),500,10000,i); }); function rotate(elem1,speed,timeout,i){ elem1.animate({'marginLeft':'18px','width':'0px'},speed,function(){ var other; if(elem1.parent().attr('id') == 'ad_1') other = $('#ad_2').children('img').eq(i); else other = $('#ad_1').children('img').eq(i); other.animate({'marginLeft':'0px','width':'266px'},speed,function(){ var f = function() { rotate(other,speed,timeout,i) }; setTimeout(f,timeout); }); }); } }); </script> </body> </html> And here is a working example: http://www.santamarinas.com/RS/Tests/Billboard/ Thank you in advance for your help!! Hello all, Firstly apologies for my javascript ignorance - I'm not a programmer, just someone thrust into programming since there's no-one else at my company who can do it. I found a nice js script online for a drop-down menu where the drop downs both expand to their full size and fade-in (very quickly) from transparent. The script in action can be seen on the script writer's site he http://sandbox.leigeber.com/dropdown-menu/index.html and the script is: Code: var menu=function(){ var t=15,z=50,s=6,a; function dd(n){this.n=n; this.h=[]; this.c=[]} dd.prototype.init=function(p,c){ a=c; var w=document.getElementById(p), s=w.getElementsByTagName('ul'), l=s.length, i=0; for(i;i<l;i++){ var h=s[i].parentNode; this.h[i]=h; this.c[i]=s[i]; h.onmouseover=new Function(this.n+'.st('+i+',true)'); h.onmouseout=new Function(this.n+'.st('+i+')'); } } dd.prototype.st=function(x,f){ var c=this.c[x], h=this.h[x], p=h.getElementsByTagName('a')[0]; clearInterval(c.t); c.style.overflow='hidden'; if(f){ p.className+=' '+a; if(!c.mh){c.style.display='block'; c.style.height=''; c.mh=c.offsetHeight; c.style.height=0} if(c.mh==c.offsetHeight){c.style.overflow='visible'} else{c.style.zIndex=z; z++; c.t=setInterval(function(){sl(c,1)},t)} }else{p.className=p.className.replace(a,''); c.t=setInterval(function(){sl(c,-1)},t)} } function sl(c,f){ var h=c.offsetHeight; if((h<=0&&f!=1)||(h>=c.mh&&f==1)){ if(f==1){c.style.filter=''; c.style.opacity=1; c.style.overflow='visible'} clearInterval(c.t); return } var d=(f==1)?Math.ceil((c.mh-h)/s):Math.ceil(h/s), o=h/c.mh; c.style.opacity=o; c.style.filter='alpha(opacity='+(o*100)+')'; c.style.height=h+(d*f)+'px' } return{dd:dd} }(); with Code: var menu=new menu.dd("menu"); menu.init("menu","menuhover"); used on my html page to call the script. I'm using the script exactly as written and exactly as it is on the dude's demo page for it. However, some of my sub-menu items are wider than their parent items and in IE7 this means they are bound to the width of the parent until the animations have finished, and then pop-out to their full width (NB not an issue in FF3). I'm actually not too fussed about either the fade in or expand out effects (they'd be nice, but not at the expense of the IE7 bug) so I simply wanted to know what I should do to the script to turn off the effects, or make them instant - ie reduce the length of the effect to as short as possible. I understand I can get rid of the bug by specifying a width for the ul element in my css, but I'd rather not do that if I can help it. I'd appreciate anyone's insight on this. Thanks Tom Not done any coding for a LONG time. I want to get the value of the opacity for a element. I'm using Nightly 9.0a1. Also, from what I have read Firefox should us this to SET the opacity style: Code: obj.style.opacity = opacity/100; But this does not see to work in the CSS. In the CSS the value ranges from 0 to 1. So 50% would be 0.5 My current function stops working before executing the alert command. I'm guessing i'm trying to get the style value wrong? Code: function fadeByid(objId) { if (document.getElementById) { obj = document.getElementById(objId); opacity = obj.style.opacity; alert(opacity); if (opacity >= 100) { setOpacity(obj, opacity); opacity -= 10; window.setTimeout("fadeByid('"+objID+"','"+opacity+")", 100); } } } Hey Guys, I'm pretty new to Javascript, maybe you can help me with a small piece. I have 4 images, they are displayed 2x2. Initially they rest at 0.3 opacity.When you hover over one, it goes to 1 opacity. When you click an image, it becomes the selected image and stays at 1 opacity. I have this all working fine. My problem is, when you click another image, the "selected" image stays at 1 opacity until you roll over it again. I want it to automatically fade back to 0.3 opacity when another image is selected. I will attach my code: Code: <style type="text/css"> .MouseOver { opacity:0.3; filter:alpha(opacity=30); } </style> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"> </script> <script type="text/javascript"> currentImage=null; $(function() { $('.MouseOver').each(function() { $(this).hover( function() { $(this).stop().animate({ opacity: 1.0 }, 300); }, function() { if(currentImage != this) { $(this).stop().animate({ opacity: 0.3 }, 300); } }) }); }); function doSomething(pic) { currentImage=pic; } </script> The images then have .MouseOver class and the onClick calls the doSomething function. I'd appreciate any help you can give me. Thanks so much. Hey everyone, What I need to do is have my website so when it loads on the homepage for the first time its starts of with a blank (specified color) background, then the logo fades in the middle, then a few seconds later that all fades away to reveal the website. Is this possible without forwarding to separate pages and without flash? Thanks all. Hey everyone, For a site I'm currently working on I needed the index page to start out blacked out, have an animated logo fade in, then fade out again before the main page contents fading up all without redirecting etc. I used the following to do this and it works except for one thing. Once the overlay div has faded, it seems to take around 20-30 seconds before the main contents becomes usable. Any ideas for a fix? Code: <body style="overflow:hidden;" onload="MM_preloadImages('images/enter_o.png')"> <div id="overlay" ><img border="0" src="images/animatelogo.gif" alt="img" /></div> <script type="text/javascript"> /*<![CDATA[*/ function fade(o){ var oop=this,obj=document.getElementById(o.ID),img=obj.getElementsByTagName('IMG')[0]; this.obj=obj; var img=document.getElementById(o.ID).getElementsByTagName('IMG')[0]; img.style.top=this.wwhs()[1]/2-img.height/2+'px'; this.mS=o.Duration||1000; this.animate(img,new Date(),0,100,true); img.style.visibility='visible'; } fade.prototype={ animate:function(obj,srt,f,t,sc){ var oop=this,ms=new Date().getTime()-srt,now=Math.floor(sc=='s'?(t-f)*Math.sin(this.inc*ms)+f:sc=='c'?t-(t-f)*Math.cos(this.inc*ms):(t-f)/this.mS*ms+f); this.now=Math.max(now,f<0||t<0?now:0); obj.style.filter='alpha(opacity='+now+')'; obj.style.opacity=obj.style.MozOpacity=obj.style.WebkitOpacity=obj.style.KhtmlOpacity=now/100-.001; if (ms<this.mS){ this.dly=setTimeout(function(){ oop.animate(obj,srt,f,t,sc); },10); } else if (sc){ this.animate(this.obj,new Date(),100,0,false); } else { document.body.removeChild(obj); } }, wwhs:function(){ if (window.innerHeight) return [window.innerWidth-10,window.innerHeight-10,window.pageXOffset,window.pageYOffset]; else if (document.documentElement.clientHeight) return [document.documentElement.clientWidth-10,document.documentElement.clientHeight-10,document.documentElement.scrollLeft,document.documentElement.scrollTop]; return [document.body.clientWidth,document.body.clientHeight,document.body.scrollLeft,document.body.scrollTop]; } } setTimeout(function(){ new fade({ ID:'overlay', Duration:11500 }); },10); /*]]>*/ </script> <table class="mainbody" width="900" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td align="center"> <div style="position:absolute; left: 50%; top: 50%; margin: -197px 0 0 -300px; height: 394px; width: 600px; text-align:center;" /> <iframe src="http://player.vimeo.com/video/******44?title=0&byline=0&portrait=0&color=000000" width="600" height="328" frameborder="0"></iframe> <br /><br /><a href="films.php" class="entrytext"><img src="images/enter.png" id="Image1" onmouseover="MM_swapImage('Image1','','images/enter_o.png',1)" onmouseout="MM_swapImgRestore()"></a></div> </td> </tr> </table> </body> So as a breakdown, the page should load black, remain black as a logo fades into it, plays through and fades out, followed by the main content fading up and becoming usable. All this happens as desired except after the main content is visible it takes ages to become active as if the overlay is still there :-\ Thanks Hi guys! I'm trying to make a div layer (id "tehz") fade in using Java. Problem is, it doesn't go through the animation, it just skips to the last stage. If I put an alert to show me the value of "cat" at every step it works just fine. Can anyone please tell me what's the matter? Code: function vis(cat) { if(cat<=90) { // alert(cat) document.getElementById("tehz").style.opacity=cat/100; document.getElementById("tehz").style.filter="alpha(opacity="+cat+")" cat=cat*1+1 setTimeout(vis(cat),1000); } } Hi, I am having difficulty (tearing my hair out) with this problem. I have written a page as a learning experince for JavaScript. The page is here. The fade in works perfectly for ONLOAD and for ONMOUSEOVER but not for ONMOUSEOUT. The JavaScript code is as follows: Code: var d_opacity ; var e_element ; var t_timeout ; function fadeInElement(s_element_to_fade_in) { d_opacity = 0.25 ; e_element = document.getElementById(s_element_to_fade_in) ; (e_element.style).display = "" ; (e_element.style).opacity = d_opacity ; t_timeout = setTimeout("fadeIn()", 125) ; } function fadeIn() { if (d_opacity == 1.0) { clearTimeout(t_timeout) ; } else { d_opacity += 0.075 ; (e_element.style).opacity = d_opacity ; t_timeout = setTimeout("fadeIn()", 125) ; } } function fadeOutElement(s_element_to_fade_out) { e_element = document.getElementById(s_element_to_fade_out) ; d_opacity = (e_element.style).opacity ; t_timeout = setTimeout("fadeOut()", 125) ; // (e_element.style).display = "none" ; } function fadeOut() { if (d_opacity == 0.25) { clearTimeout(t_timeout) ; (e_element.style).display = "none" ; } else { d_opacity -= 0.075 ; (e_element.style).opacity = d_opacity ; t_timeout = setTimeout("fadeOutn()", 125) ; } } When I use the commented out line in fadeOutElement(), the menu disappears which says to me ONMOUSEOUT is being triggered correctly, but if I do the fading out code, it does nothing. Any help greatly appreciated. So far I have this written up which does work well. However, the problem is if one toggles the fadeOut function while the fadeIn function is still in action. That causes the functions to collide and have to element being faded start flashing or freezing. Is there a simple way to prevent this? Thank you. Code: function fadeIn(elementId) { var element = document.getElementById(elementId); if(element.style.display === 'none') { element.style.display = 'block'; element.style.opacity = '0'; } if(element.style.opacity < 1) { var opacityFloat = parseFloat(element.style.opacity); element.style.opacity = opacityFloat + 0.1; setTimeout("fadeIn('" + elementId + "')", 50); } } function fadeOut(elementId) { var element = document.getElementById(elementId); if(element.style.opacity > 0) { var opacityFloat = parseFloat(element.style.opacity); element.style.opacity = opacityFloat - 0.1; setTimeout("fadeOut('" + elementId + "')", 50); } if(element.style.opacity == 0) { element.style.display = 'none'; } } How am I able to have a gallery of images fading in and out as the background of a DIV? It's currently just a static background using CSS. You can view the HTML page in question he http://aksdesigns.co.uk/temp/template.html The DIV container is the one with the ID of #MainContent Code: #MainContent { width: 980px; height: 550px; margin: 0 auto; padding: 0px; background-image: url(images/Content-bg-1.jpg); background-repeat: no-repeat; background-position: top center; border-left: 2px solid #153365; border-right: 1px solid #FFF; } It probably couldn't be done using CSS be how could I achieve this with Javascript? I've prepared the following page: http://www.ko-go.gr/restaurant/index1a.html but I would prefer the background images to fade in and out rather than change abruptly. I've spent hours searching for appropriate code, but have met a dead end so far. Incidentally, I presume that the delay before the first background image appears is because of all the images pre-loading. Can anyone suggest a way to immediately display the first image? Thanks for taking the time to read this... I have a jQuery Slideshow script that i'm using and it's all done in 6 lines. Code: $(function(){ $('.fadein img:gt(0)').hide(); setInterval(function(){ $('.fadein :first-child').fadeOut() .next('img').fadeIn() .end().appendTo('.fadein');}, 3000); }); </script> I'm having a problem centering it on my website and keeping the images behind each other every time a picture changes. The CSS uses absolute positioning to hide the images behind each other. The fadeIn part of the CSS uses relative positioning. The CSS for the fading image slideshow is at the end of the css. Code: .fadein { position:relative; width:100%; height:300px; background-color:#000; overflow:hidden } .fadein img { position:relative; left:300px; width:auto; text-align:center; top:0px; } jonathaneiger.com |