JavaScript - I Simply Cannot Get Color Animation Plugin To Work...please Help.
hey.
i'm not a code expert or anything but i here's what i'm trying to do: i set up this blog using weebly.com: http://noamagger.weebly.com and i wanna add color animations to the post titles and some buttons and i can't seem to get it working. here's what i did: added this to the html head: <script type="text/javascript" src="http://www.jonathanlax.com/nmblog/js/jquery-1.3.2.js"></script> <script type="text/javascript" src="http://www.jonathanlax.com/nmblog/js/jquery.color.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#blog-read-more-link").hover(function() { $(this).stop().animate({ backgroundColor: "#53b9df"}, 800); },function() { $(this).stop().animate({ backgroundColor: "#e7e7e7" }, 800); }); }); </script> tried making the "read more" button's background to change colors on hover. it simply does not work for me. firebug gives me this: $("#blog-read-more-link") is null $("#blog-read-more-link").hover(function() { i've tried so many things already and nothing seems to work... please help! thanx Similar Tutorialson my site he http://www.jbiddulph.com/niche/ I would like to apply an opacity on my navigation roll over, can someone help me here?! here is the code for my Home link: Code: $('#nav ul li.home').hover( function() { $(this).stop().animate({backgroundColor:'#ff8300'}, 1300); }, function () { $(this).stop().animate({backgroundColor:'#666666'}, 100); }); I' am trying to do a frame by frame animation, lik an animated gif. I am using svg (vector graphics) and IE9 has native support for svg. The code functions in every other browser but IE9 plays the animation once then nothing. If you would like to try and not have svg files you can use whatever gif,jpg or png just put an img-tag where i have embed. Code: <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Animation</title> <style type="text/css"> /*One div per image all uses this class*/ .eyesPos { position:absolute; width:80px; height:50px; z-index:1; left: 0px; top: 0px; } #eye_wrapper{/*This is a master div for easy placement of the others*/ position:absolute; width:80px; height:50px; z-index:2; left: 275px; top: 200px; } </style> <script> var eyes=["a","b","c","d"];//Image id in this array var startAnim=setInterval(visaOga,100);//Animation speed function visaOga(){ document.getElementById(eyes.splice(0,1)).style.display="block"; if(eyes.length==0){ document.getElementById("a").style.display="none"; document.getElementById("b").style.display="none"; document.getElementById("c").style.display="none"; dBort = function(){ document.getElementById("d").style.display="none"; eyes=["a","b","c","d"]; } setTimeout(dBort,1500);//So last image is shown 1.5 sec return;//Aborts - dBort -. Sequence can start over if(document.getElementById("d").style.display=="none"){ startAnim;//Strts sequence if last image invisible } } } </script> </head> <body> <!--Images in own div invisible at start--> <div id="eye_wrapper"> <div class="eyesPos" id="a" style= display:none;> <embed src="0.svg" width="80" height="50" /> </div> <div class="eyesPos" id="b" style= display:none;> <embed src="1.svg" width="80" height="50" /> </div> <div class="eyesPos" id="c" style= display:none;> <embed src="2.svg" width="80" height="50" /> </div> <div class="eyesPos" id="d" style= display:none;> <embed src="3.svg" width="80" height="50" /> </div> </div> </body> </html> Hello! I am new to the boards, I am a graphic and web designer. Been designing and developing web sites since 2001. I have fun doing it and was lucky enough to have someone hire me to do it and get paid for it. The reason I signed up to the boards is so that I can search for some help since I am starting to learn jQuery I am having a little bit of trouble with a page I am working on and was hoping someone would be able to help me out! The problem: I have a spry collapsable panel with 4 panels, in the panels I have jQuery carousel plugins with the thumbs plugin. The problem I am having is that I want the carousel in the 4 panels like I mentioned before but I can only get one of the panels to function fully. The other three loses their forward back functions. I tried copying the code for the first one and just renaming the classes and functions so it would separate the two. The thumbs plugin will still work, I just can not get the carousel function to repeat on another one. I will post the code I have left off with. If you need to see the page you can message me. Thanks for reading and if you can help it will be great! Here is the java: Code: $(document).ready(function () { $('.infiniteCarousel').infiniteCarousel(); }); $.fn.infiniteCarousel = function () { function repeat(str, num) { return new Array( num + 1 ).join( str ); } return this.each(function () { var $wrapper = $('> div', this).css('overflow', 'hidden'), $slider = $wrapper.find('> ul'), $items = $slider.find('> li'), $single = $items.filter(':first'), singleWidth = $single.outerWidth(), visible = Math.ceil($wrapper.innerWidth() / singleWidth), currentPage = 1, pages = Math.ceil($items.length / visible); if (($items.length % visible) != 0) { $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible))); $items = $slider.find('> li'); } $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned')); $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned')); $items = $slider.find('> li'); // reselect $wrapper.scrollLeft(singleWidth * visible); function gotoPage(page) { var dir = page < currentPage ? -1 : 1, n = Math.abs(currentPage - page), left = singleWidth * dir * visible * n; $wrapper.filter(':not(:animated)').animate({ scrollLeft : '+=' + left }, 500, function () { if (page == 0) { $wrapper.scrollLeft(singleWidth * visible * pages); page = pages; } else if (page > pages) { $wrapper.scrollLeft(singleWidth * visible); // reset back to start position page = 1; } currentPage = page; }); return false; } $wrapper.after('<a class="arrow back"><</a><a class="arrow forward">></a>'); $('a.back', this).click(function () { return gotoPage(currentPage - 1); }); $('a.forward', this).click(function () { return gotoPage(currentPage + 1); }); $(this).bind('goto', function (event, page) { gotoPage(page); }); }); }; //Carousel 2 $('.infiniteCarouselTwo').infiniteCarouselTwo(); $.fn.infiniteCarouselTwo = function () { function repeat(str, num) { return new Array( num + 1 ).join( str ); } return this.each(function () { var $wrapperTwo = $('> div', this).css('overflow', 'hidden'), $slider = $wrapperTwo.find('> ul'), $items = $slider.find('> li'), $single = $items.filter(':first'), singleWidth = $single.outerWidth(), visible = Math.ceil($wrapperTwo.innerWidth() / singleWidth), currentPage = 1, pages = Math.ceil($items.length / visible); if (($items.length % visible) != 0) { $slider.append(repeat('<li class="empty" />', visible - ($items.length % visible))); $items = $slider.find('> li'); } $items.filter(':first').before($items.slice(- visible).clone().addClass('cloned')); $items.filter(':last').after($items.slice(0, visible).clone().addClass('cloned')); $items = $slider.find('> li'); // reselect $wrapperTwo.scrollLeft(singleWidth * visible); function gotoPage(page) { var dir = page < currentPage ? -1 : 1, n = Math.abs(currentPage - page), left = singleWidth * dir * visible * n; $wrapperTwo.filter(':not(:animated)').animate({ scrollLeft : '+=' + left }, 500, function () { if (page == 0) { $wrapperTwo.scrollLeft(singleWidth * visible * pages); page = pages; } else if (page > pages) { $wrapperTwo.scrollLeft(singleWidth * visible); // reset back to start position page = 1; } currentPage = page; }); return false; } $wrapperTwo.after('<a class="arrow back"><</a><a class="arrow forward">></a>'); $('a.back', this).click(function () { return gotoPage(currentPage - 1); }); $('a.forward', this).click(function () { return gotoPage(currentPage + 1); }); $(this).bind('goto', function (event, page) { gotoPage(page); }); }); }; Here is the CSS: Code: .infiniteCarousel { width: 395px; position: relative; } .infiniteCarousel .wrapper { width: 825px; /* .infiniteCarousel width - (.wrapper margin-left + .wrapper margin-right) */ overflow: auto; min-height: 10em; position: absolute; top: 0; margin-top: 0; margin-right: 40px; margin-bottom: 0; margin-left: 40px; left: 20px; } .infiniteCarousel ul a img { -moz-border-radius: 5px; -webkit-border-radius: 5px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; } .infiniteCarousel .wrapper ul { width: 9999px; list-style-image:none; list-style-position:outside; list-style-type:none; margin:0; padding:0; position: absolute; top: 0; } .infiniteCarousel ul.thumb li { display:block; float:left; padding: 10px; height: 85px; width: 85px; -ms-interpolation-mode: bicubic; } .infiniteCarousel ul.thumb li a img { display:block; } .infiniteCarousel .arrow { display: block; height: 36px; width: 37px; text-indent: -999px; position: absolute; top: 25px; cursor: pointer; background-image: url(../images/arrow.png); background-repeat: no-repeat; background-position: 0 0; } .infiniteCarousel .forward { background-position: 0 0; right: 0; background-image: url(../images/arrow.png); background-repeat: no-repeat; left: 910px; } .infiniteCarousel .back { background-position: 0 0px; left: 0; background-image: url(../images/arrow-back.png); background-repeat: no-repeat; } .infiniteCarousel .forward:hover { background-position: 0 0px; background-image: url(../images/arrow.png); background-repeat: no-repeat; } .infiniteCarousel .back:hover { background-position: 0 0px; background-image: url(../images/arrow-back.png); } ul.thumb li img.hover { background:url(thumb_bg.png) no-repeat center center; border: none; } #main_view { } /* Carousel Two */ .infiniteCarouselTwo { width: 395px; position: relative; } .infiniteCarouselTwo .wrapperTwo { width: 825px; /* .infiniteCarouselTwo width - (.wrapperTwo margin-left + .wrapperTwo margin-right) */ overflow: auto; min-height: 10em; position: absolute; top: 0; margin-top: 0; margin-right: 40px; margin-bottom: 0; margin-left: 40px; left: 20px; } .infiniteCarouselTwo ul a img { -moz-border-radius: 5px; -webkit-border-radius: 5px; border-top-style: none; border-right-style: none; border-bottom-style: none; border-left-style: none; } .infiniteCarouselTwo .wrapperTwo ul { width: 9999px; list-style-image:none; list-style-position:outside; list-style-type:none; margin:0; padding:0; position: absolute; top: 0; } .infiniteCarouselTwo ul.thumbTwo li { display:block; float:left; padding: 10px; height: 85px; width: 85px; -ms-interpolation-mode: bicubic; } .infiniteCarouselTwo ul.thumbTwo li a img { display:block; } .infiniteCarouselTwo .arrow { display: block; height: 36px; width: 37px; text-indent: -999px; position: absolute; top: 25px; cursor: pointer; background-image: url(../images/arrow.png); background-repeat: no-repeat; background-position: 0 0; } .infiniteCarouselTwo .forward { background-position: 0 0; right: 0; background-image: url(../images/arrow.png); background-repeat: no-repeat; left: 910px; } .infiniteCarouselTwo .back { background-position: 0 0px; left: 0; background-image: url(../images/arrow-back.png); background-repeat: no-repeat; } .infiniteCarouselTwo .forward:hover { background-position: 0 0px; background-image: url(../images/arrow.png); background-repeat: no-repeat; } .infiniteCarouselTwo .back:hover { background-position: 0 0px; background-image: url(../images/arrow-back.png); } ul.thumbTwo li img.hover { background:url(thumb_bg.png) no-repeat center center; border: none; } #main_viewTwo { } Here is the HTML: Code: <div id="around" class="CollapsiblePanel"> <div class="CollapsiblePanelTabBlue" tabindex="1">Around town</div> <div class="CollapsiblePanelContent"> <div id="main_viewTwo"> <img src="images/placeholder.jpg" alt="placeholder" width="938" height="273" /> </div> <!-- Start Carousel --> <div class="infiniteCarouselTwo"> <div class="wrapperTwo"> <ul class="thumbTwo"> <li><a href="images/placeholder.jpg"><img src="images/carouhold1.png" alt="Holder image" width="51" height="51" /></a>1</li> <li><a href="images/placeholder2.jpg"><img src="images/carouhold2.png" width="51" height="51" alt="Holder image" /></a>2</li> <li><a href="images/placeholder3.jpg"><img src="images/carouhold3.png" width="51" height="51" alt="Holder image" /></a>3</li> <li><a href="images/placeholder4.jpg"><img src="images/carouhold4.png" width="51" height="51" alt="Holder image" /></a>4</li> <li><a href="images/placeholder5.jpg"><img src="images/carouhold5.png" width="51" height="51" alt="Holder image" /></a>5</li> <li><a href="images/placeholder6.jpg"><img src="images/carouhold6.png" width="51" height="51" alt="Holder image" /></a>6</li> <li><a href="images/placeholder7.jpg"><img src="images/carouhold7.png" width="51" height="51" alt="Holder image" /></a>7</li> <li><a href="images/placeholder8.jpg"><img src="images/carouhold8.png" width="51" height="51" alt="Holder image" /></a>8</li> <li><a href="images/placeholder9.jpg"><img src="images/carouhold9.png" width="51" height="51" alt="Holder image" /></a>9</li> <li><a href="images/placeholder10.jpg"><img src="images/carouhold10.png" width="51" height="51" alt="Holder image" /></a>10</li> <li><a href="images/placeholder11.jpg"><img src="images/carouhold11.png" width="51" height="51" alt="Holder image" /></a>11</li> <li><a href="images/placeholder12.jpg"><img src="images/carouhold12.png" width="51" height="51" alt="Holder image" /></a>12</li> <li><a href="images/placeholder13.jpg"><img src="images/carouhold13.png" width="51" height="51" alt="Holder image" /></a>13</li> <li><a href="images/placeholder14.jpg"><img src="images/carouhold14.png" width="51" height="51" alt="Holder image" /></a>14</li> <li><a href="images/placeholder15.jpg"><img src="images/carouhold15.png" width="51" height="51" alt="Holder image" /></a>15</li> <li><a href="images/placeholder16.jpg"><img src="images/carouhold16.png" width="51" height="51" alt="Holder image" /></a>16</li> </ul> </div> </div> <!--End Carousel--> </div> </div> <div id="campus" class="CollapsiblePanel"> <div class="CollapsiblePanelTabGreen" tabindex="1">Campus life</div> <div class="CollapsiblePanelContent"> <div id="main_view"> <img src="images/placeholder.jpg" alt="placeholder" width="938" height="273" /> </div> <!-- Start Carousel --> <div class="infiniteCarousel"> <div class="wrapper"> <ul class="thumb"> <li><a href="images/placeholder.jpg"><img src="images/carouhold1.png" alt="Holder image" width="51" height="51" /></a>1</li> <li><a href="images/placeholder2.jpg"><img src="images/carouhold2.png" width="51" height="51" alt="Holder image" /></a>2</li> <li><a href="images/placeholder3.jpg"><img src="images/carouhold3.png" width="51" height="51" alt="Holder image" /></a>3</li> <li><a href="images/placeholder4.jpg"><img src="images/carouhold4.png" width="51" height="51" alt="Holder image" /></a>4</li> <li><a href="images/placeholder5.jpg"><img src="images/carouhold5.png" width="51" height="51" alt="Holder image" /></a>5</li> <li><a href="images/placeholder6.jpg"><img src="images/carouhold6.png" width="51" height="51" alt="Holder image" /></a>6</li> <li><a href="images/placeholder7.jpg"><img src="images/carouhold7.png" width="51" height="51" alt="Holder image" /></a>7</li> <li><a href="images/placeholder8.jpg"><img src="images/carouhold8.png" width="51" height="51" alt="Holder image" /></a>8</li> <li><a href="images/placeholder9.jpg"><img src="images/carouhold9.png" width="51" height="51" alt="Holder image" /></a>9</li> <li><a href="images/placeholder10.jpg"><img src="images/carouhold10.png" width="51" height="51" alt="Holder image" /></a>10</li> <li><a href="images/placeholder11.jpg"><img src="images/carouhold11.png" width="51" height="51" alt="Holder image" /></a>11</li> <li><a href="images/placeholder12.jpg"><img src="images/carouhold12.png" width="51" height="51" alt="Holder image" /></a>12</li> <li><a href="images/placeholder13.jpg"><img src="images/carouhold13.png" width="51" height="51" alt="Holder image" /></a>13</li> <li><a href="images/placeholder14.jpg"><img src="images/carouhold14.png" width="51" height="51" alt="Holder image" /></a>14</li> <li><a href="images/placeholder15.jpg"><img src="images/carouhold15.png" width="51" height="51" alt="Holder image" /></a>15</li> <li><a href="images/placeholder16.jpg"><img src="images/carouhold16.png" width="51" height="51" alt="Holder image" /></a>16</li> </ul> </div> </div> <!--End Carousel--> </div> </div> Ask me if you need any more information from me. Like I said if you need to see the page message me! It is not a site I want to make too public at the moment for some reasons of who I work for. So, i have this code which retrieves php files for me using jquery and id love to get it working with Jquery history plugin. I tried modifying the code i got from the ajax demo to work for me, but i just couldnt do it as i do not know any javascript really.. ( actually what i tried was simply to change "#ajax-links a" to "#menu li a" and .html to .php ..but nothing.. :rolleyes: Id be very gratefull if someone would help me out with this one. All related code can be found bellow (the ones that should be needed anyways): This is the code that retrieves php files inside "#content" when item from "#menu li a" with the specified id is clicked Code: $(document).ready(function(){ //References var change = $("#menu li a"); var loading = $("#loading"); var content = $("#content"); //Manage click events change.click(function(){ //show the loading bar showLoading(); //load selected section if(this.id == "home") { change.load(this.className='current-page'); content.slideUp(); content.load("pages/index.php", hideLoading); content.slideDown(); } else if(this.id == "secondpage") { change.load(this.className='current-page'); content.slideUp(); content.load("pages/secondpage.php", hideLoading); content.slideDown(); } else { //hide loading bar if there is no selected section hideLoading(); } }); //show loading bar function showLoading(){ loading .css({visibility:"visible"}) .css({opacity:"1"}) .css({display:"block"}) ; } //hide loading bar function hideLoading(){ loading.fadeTo(1000, 0); }; }); Heres the structure of the menu/content Code: <ul id="menu"> <li><a id="home" class="normal" href="#Home"></a></li> <li><a id="secondpage" class="normal" href="#Secondpage"></a></li> </ul> <div id="content"> <ul id="sec-menu"> <li><a id="link1" class="normal" href="#">Link1</a></li> <li><a id="link2" class="normal" href="#">Link2</a></li> </ul> </div> Heres the code that jquery history plugin uses in demo for ajax Code: jQuery(document).ready(function($) { function load(num) { $('#content').load(num +".html"); } $.history.init(function(url) { load(url == "" ? "1" : url); }); $('#ajax-links a').live('click', function(e) { var url = $(this).attr('href'); url = url.replace(/^.*#/, ''); $.history.load(url); return false; }); }); I have a picture of a pinwheel on my website that I want to spin onMouseover. Can this be done with JavaScript?
I want to create some type of seasonal feel on my Web page where there are falling leaves. I presently have 6 different gif images of leaves that I know I will probably have to load into an array. I also know that I will have to figure out the maximum width & height of the screen, which is different in Internet Explorer and other browsers. My goal is to load the leaves randomly as well using 'Math.floor(Math.random()*6)', if that is correct. Beyond that, I am lost on how to manipulate the Web page to make this animation occur. Any help would be appreciated. Thank you. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Autumn</title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" /> <script type="text/javascript"> <!--Hide from incompatible browsers /* <![CDATA[ */ var widthMax=0; var heightMax=0; var leavesLoaded = new Array(6); for (var i=0; i<6; ++i) { leavesLoaded[i] = new Image(); leavesLoaded[i].src = "leaf" + (i+1) + ".gif"; } function setLeaf() { if (navigator.appName == "Microsoft Internet Explorer") { widthMax=document.documentElement.clientWidth; heightMax=document.documentElement.clientHeight; } else { widthMax=window.innerWidth-14; heightMax=window.innerHeight; } setTimeout('fallingLeaves()',400); } /* ]]> */ // Stop hiding from incompatible browsers --> </script> </head> <body onload="setLeaf();" > <p><img src="images/leaf1.gif" id="leaf" style="position:absolute; left:0px; top:0px; visibility:hidden" alt="Image of a Leaf" /></p> </body> </html> Hi, I have created an animation exercise for an eLearning lesson in a program that uses JavaScript as the scripting for a Windows executable. A retired social worker who creates these eLearning materials as give-away's to help people in the community improve health, it would be a big help to reaching more people if instead of a Windows executable version, the animation could be developed in a web page. A lot more people could view the eLearning and try this exercise which trains people in pacing their breathing. The animation has a 300X300 circle on the canvas with a couple of text input boxes and a start button. The JS < 50 lines of script, but since it was not developed for a web page, it has no tags and it depends on objects like the circle or button (or 2 audio files to create the inhale/exhale sounds) that were already placed on the canvas in the Windows executable program. I'm not very skilled using Dreamweaver CS5, but with help, reading, references can try to convert this JS into a web version, if it's possible. Not sure how to do this and would appreciate any help. I am adding a screenshot of the interface and the JS functions that are called by the start button. //JS: ( bar1 is the variable entered by the use as breaths per minute-BPM; //time1 is the exercise length; the variables initially are set as follows: //time1=15, //volume=100) var time1 function minuteTimer() { breakLoop = false stopLoop = false fork (calcBreathing) for (var i=0;i<time1;i++) { wait(60) breakLoop = true Submit.Show() Text122.Show() Text12.Show() TextInput22.Show() TextInput2.Show() Submit2.Hide() TextInput2.SetTransparency(0,false) TextInput22.SetTransparency(0,false) Text12.SetTransparency(0,false) Text122.SetTransparency(0,false) Text5.SetTransparency(0,false) Frame12.SetTransparency(0,false) Submit.SetTransparency(0,false) TextInput2.Enable(true) TextInput22.Enable(true) Debug.trace("\n minutes elapsed "+(i+1)+"\n") } stopLoop = true } function calcBreathing() { var bar2 = 60/bar1 for (loop = 0;loop<bar1;loop++) { mySound.Play(1,volume) Vector8.Scale(.5,.5, bar2*.3) mySound.Stop() wait (bar2*.05) mySound2.Play(1,volume) Vector8.Scale(-.5,-.5,bar2*.6) mySound2.Stop() wait (bar2*.05) if (breakLoop) break } breakLoop = false if (bar1 > 6) bar1-- if (!stopLoop) calcBreathing() } Any help appreciated. Thanks very much. Kind Regards, saratogacoach Hi! New to JS... have been trying to rework this to call additional, independent sets of colors to cycle through (so it would loop thru a set of grays, a set of primary colors, etc). I would use perhaps a different function name in the HTML to call different sets of colors. If this is more complex than I think it is, I think 3 sets would be plenty. Would be hugely grateful for any help, thanks so much in advance. (demo link of script in current state at bottom) Code: <html><head><title></title> <script language=javascript> colors = ["#cacdca", "#b2b4b2", "#969896", "#7d7f7d", "#ffff00"]; cRGB = []; function toRGB(color){ var rgb = "rgb(" + parseInt(color.substring(1,3), 16) + ", " + parseInt(color.substring(3,5), 16) + ", " + parseInt(color.substring(5,7), 16) + ")"; return rgb; } for(var i=0; i<colors.length; i++){ cRGB[i] = toRGB(colors[i]); } function changeColor(target){ var swapper = navigator.appVersion.indexOf("MSIE")!=-1 ? toRGB(document.getElementById(target).style.backgroundColor) : document.getElementById(target).style.backgroundColor; var set = false; var xx; for(var i=0; i<cRGB.length; i++){ if(swapper == cRGB[i]){ if(((i+1)) >= cRGB.length){ xx = 0; }else{ xx = i+1; } document.getElementById(target).style.backgroundColor = colors[xx]; document.getElementById(target).style.backgroundImage.show; set = true; i=cRGB.length; } } set ? null : document.getElementById(target).style.backgroundColor = colors[1]; } </SCRIPT> </head> <body bgcolor="#333333"> <div> <div id="a1" onmouseover=changeColor(this.id); style="left: 120px; background-image: url(background1.png); width: 180px; background-repeat: no-repeat; position: relative; height: 80px; background-color: none"></div> <div id=a2 onmouseover=changeColor(this.id); style="left: 120px; background-image: url(background2.gif); width: 180px; background-repeat: no-repeat; position: relative; height: 80px; background-color: #666633"></div> <div id=a3 onmouseover=changeColor(this.id); style="left: 120px; background-image: url(background3.png); width: 180px; background-repeat: no-repeat; position: relative; height: 80px; background-color: #666633"></div></div> </body> </html> Demo: http://theclutch.com/rollover_color_..._bgndimage.htm Hi, I'm faced with a problem trying to set background color under IE7. I have the following Javascript: Code: function showLayer793BKColor(id) { var txtObj = document.all(id); if (txtObj.style.display == 'none') { txtObj.style.display = '' txtObj.style.backgroundColor = 'grey'; } } function hideLayer793BKColor(id) { var txtObj = document.all(id); if ( txtObj.style.backgroundColor == 'grey' ) txtObj.style.display = 'none'; } These functions are used to show or hide div blocks. These blocks are, for example, specified in the following way: Code: <div id="l_gct5tekst" style="display:none"> <b>GCT 5. Eerste verkenning problematiek</b> and, for example, Code: <div id="l_Keuze" style="display:none"> <br/> <b>GCT 5</b> <br/> </div> The whole configuration works smoothly when using IE8. However, when using IE7 I get an error msg like "Invalid value for property". When I use the Color propert iso the BackgroundColor property I get no error anymore but of course I don't have a background color anymore then. In what way can I specify the use of a background color under IE7 ? Or is just not possible in one way or the other. Furthermore, what more differences between JS under IE7 and IE8 do I have to take into account ? Do I also have to rewrite my div block in some way (using some attribs ?) to cope with IE7 ? Thanks in advance, Diederick van Elst Hello readers! I made some animation code Code: for (var i = 1; i < 8; i++) { var slc = ".s" + i; $(slc).css( { 'position':'absolute', 'top':'-300px', 'left':30*i*5, 'width':'100px', 'height':'300px', 'backgroundColor':'white' }); }; $('body').click(function() { for (var t = 1; t < 8; t++) { var asd = '.s' + t; $(asd).animate({ 'top':'0px' }, 100*t).animate({ 'top':'-300px' }, 100*t); }; }); in html there are some div tags. So, question is - How to normilize queue of animation? You see that first box moves fast and the last one moves very slow to the end. I would like boxes to move proportionally in relation to the time. Could you give some recommendations about this stuff? Anyone got any suggestions on techniques? The main one I find is to use translate to move the canvas around, which just seems odd to me. I don't even fully understand how it works. But the one I was looking at used clearRect. In examples given looked as though it had to redraw the canvas every frame. I'm just mucking around with a simple poker game, figured i'd have the table in one layer and anything that moves on a top layer? By doing that I could only clear each card as it moved around...yes? Anyone know of a better way of doing things? Hi, I will really appreciate if someone could take a look at my code below and inform me where I'm going wrong, because I can't seem to tell. The instructions a -the file starts with the text "Avalon Books" on the left edge of the page. -the text moves to the center of the page. -After the text reaches the center, the image file kids.jpg appears -Every two seconds thereafter, the image file is swapped with the next image file in the stack (there are 3 images in total). I am only posting the few relevant functions where the problem could be. All the other functions are working properly. I am new to JavaScript so any help will be really appreciated. Thank you This is the main file: Code: function placeObjects(){ var W = (0.5)*winWidth(); //gets the width of user's browser. placeIt("avalon",0,0); //placeIt function is working fine. placeIt("kids",W-75,100); placeIt("fiction",W-75,100); placeIt("nfiction",W-75,100); setZ("kids",3); //setZ function is below. setZ("fiction",2); setZ("nfiction",1); moveAvalon(); } function moveAvalon(){ var x = xCoord("avalon"); if(x <= (W-125)){ shiftIt("avalon", 10, 0); setTimeout("moveAvalon()",50); } else swapImages(); //if x is greater than W-125 } function swapImages(){ showIt("kids"); showIt("fiction"); showIt("nfiction"); setTimeout("swapIt(kids,fiction,nfiction)",2000); //syntax could be wrong here? } </script> </head> <body onload="placeObjects()"> //calls the first function on load. ............... </body> </html> and here is the second file that contains all the functions (I am posting 2 of those functions): Code: function setZ(id, z){ var object=document.getElementById(id); object.style.zIndex="z"; } function swapIt(id1, id2, id3){ var object1=getObject(id1); var object2=getObject(id2); var object3=getObject(id3); var z1; var z2; var z3; object1.style.zIndex="z1"; object2.style.zIndex="z2"; object3.style.zIndex="z3"; object1.style.zIndex="z3"; object2.style.zIndex="z1"; object3.style.zIndex="z2"; } Hi, I created JavaScript animation and the picture after animation finished disappear. Could anyone tell me or point me how to resolve this kind of issue? I tested it in IE as well as Firefox.. I could send the code but it is quite long for posting, but the screenshots from before and after animation is finished are as below. thanks in advance for any help. trotsky I have a site with a lot of animated gifs and I was wondering if there was a way to (on page load) stop all gif animations (only show first image frame). Then when you click a link, it will animate the animated gifs.
I am having some difficulty with this project. It is supposed to be an animation of falling leaves. I am very new to arrays and JavaScript, so right off the bat I know that the arrays I have are not right, or are missing something else in order for it to function. Basically all I have for this project is a still picture of the leaves and that is it. If there is someone out there with some JavaScript expertise, could you tell me what I am doing wrong? Here is the code so far, I think it is too long. Code: <script type="text/javascript"> /* <![CDATA[ */ grphcs=new Array(6) Image0=new Image(); Image0.src=grphcs[0]="images/leaf1.gif"; Image1=new Image(); Image1.src=grphcs[1]="images/leaf2.gif"; Image2=new Image(); Image2.src=grphcs[2]="images/leaf3.gif"; Image3=new Image(); Image3.src=grphcs[3]="images/leaf4.gif"; Image4=new Image(); Image4.src=grphcs[4]="images/leaf5.gif"; Image5=new Image(); Image5.src=grphcs[5]="images/leaf6.gif"; var minSpeed = 5; var maxSpeed = 30; var randomSpeed = 5; var randomSpeed2 = 10; var randomSpeed3 = 15; var randomSpeed4 = 20; var randomSpeed5 = 25; var randomSpeed6 = 30; var minHorizontal = 200; var maxHorizontal = screen.availWidth - 300; var leftPosition = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); var leftPosition2 = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); var leftPosition3 = Math.floor(Math.random() * (maxHorizontal - minHorizontal +1)) + minHorizontal); var leftPosition4 = Math.floor(Math.random() * (maxHorizontal - minHorizontal + 1)) + minHorizontal); var leftPosition5 = Math.floor(Math.random() * (maxHorizontal - minHorizontal + 1)) + minHorizontal); var leftPosition6 = Math.floor(Math.random() * (maxHorizontal - minHorizontal + 1)) + minHorizontal); var minVertical = 50; var maxVertical = screen.availHeight - 300; var topPosition = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); var topPosition2 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); var topPosition3 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); var topPosition4 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); var topPosition5 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); var topPosition6 = Math.floor(Math.rnadom() * (maxVertical - (minVertical + 1)) + minVertical); function matchLeaf() { if (navigator.appName == "Microsoft Internet Explorer") { widthMax = document.documentElement.clientWidth; heightMax = document.documentElement.clientHeight; } else { widthMax = window.innerwidth - 14; heightMax = window.innerHeight; } autumnFall(); } function autumnFall(); var fallingLeaf1 = document.getElementById("leaf1"); fallingLeaf1.style.left = leftPosition + "px"; fallingLeaf1.style.top = topPosition + "px"; fallingLeaf1.style.visibility = "visible"; topPosition += parseInt(randomspeed); leftPosition += 0; if (topPosition >= screen.availHeight - 300) { topPosition = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); leftPosition = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); leaf1.src = "images/leaf" + Math.floor(Math.random() * 6 + ".gif"; randomSpeed = Math.floor(Math.random() * maxSpeed - (minSpeed + 1)) + minSpeed); } var fallingLeaf2 = document.getElementById("leaf2"); fallingLeaf2.style.left = leftPosition2 + "px"; fallingLeaf2.style.top = topPosition2 + "px"; fallingLeaf2.style.visibility = "visible"; topPosition2 += parseInt(randomSpeed3); leftPosition2 += 0; if (topPosition2 >= screenavailHeight - 300) { topPosition2 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); leftPosition2 = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); leaf2.src = "images/leaf" + Math.floor(Math.random() * 6) + "gif"; randomSpeed2 = Math.floor(Math.random() * (maxSpeed - (minSpeed + 1)) + minSpeed); } var fallingLeaf3 = document.getElementById("leaf3"); fallingLeaf3.style.left = leftPosition3 + "px"; fallingLeaf3.style.top = topPosition3 + "px"; fallingLeaf3.stye.visibility = "visible"; topPosition3 += parseInt(randomSpeed3); leftPosition3 += 0; if (topPosition3 >= screen.availHeight - 300) { topPosition3 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); leftPosition3 = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); leaf3.src = "images/leaf" + Math.floor(Math.random() * 6 + "gif"; randomSpeed3 = Math.floor(Math.random() * (maxSpeed - (minSpeed + 1)) + minSpeed); } var fallingLeaf4 = document.getElementById("leaf4"); fallingLeaf4.style.left = leftPosition4 + "px"; fallingLeaf4.style.top = topPosition4 + "px"; fallingLeaf4.style.visibility = "visible"; topPosition4 += parseInt(randomSpeed4); leftPosition4 += 0; if (topPosition4 >= screen.availHeight - 300) { topPosition4 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); leftPosition4 = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); leaf4.src = "images/leaf" + Math.floor(Math.random() * 6 + "gif"; randomSpeed4 = Math.floor(Math.random() * (maxSpeed - (minSpeed + 1)) + minSpeed); } var fallingLeaf5 = document.getElementById("leaf5"); fallingLeaf5.style.left = leftPosition5 + "px"; fallingLeaf5.style.top = topPosition5 + "px"; fallingLeaf5.style.visibility = "visible"; topPosition5= parseInt(randomSpeed5); leftPosition5 += 0; if (topPosition5 >= screen.availHeight - 300) { topPosition5 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); leftPosition5 = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); leaf5.src = "images/leaf + Math.floor(Math.random() * 6 + "gif"; randomSpeed5 = Math.floor(Math.random() * (maxSpeed - (minSpeed + 1)) + minSpeed); } var fallingLeaf6 = document.getElementById("leaf6"); fallingLeaf6.style.left = leftPosition6 + "px"; fallingLeaf6.style.top = topPosition6 + "px"; fallingLeaf6.style.visibility = "visible"; topPosition6 = parseInt(randomSpeed6); leftPosition6 += 0; if (topPosition6 >= screen.availHeight - 300) { topPosition6 = Math.floor(Math.random() * (maxVertical - (minVertical + 1)) + minVertical); leftPosition6 = Math.floor(Math.random() * (maxHorizontal - (minHorizontal + 1)) + minHorizontal); leaf6.src = "images/leaf + Math.floor(Math.random() * 6 + "gif"; randomSpeed6 = Math.floor(math.random() * (maxSpeed - (minSpeed + 1)) + minSpeed); } } /* ]]> */ </script> </head> <body onload="setInterval('matchLeaf()', 100);"> <img id="leaf1" src="images/leaf1.gif" alt="leafone" style="position:absolute; left:100px; top:100px;" /> <img id="leaf2" src="images/leaf2.gif" alt="leaftwo" style="position:absolute; left:100px; top:100px;" /> <img id ="leaf3" src="images/leaf3.gif" alt="leafthree" style="position:absolute; left:100px; top:100px;" /> <img id="leaf4" src="images/leaf4.gif" alt="leaffour" style="position:absolute; left:100px; top:100px;" /> <img id="leaf5" src="images/leaf5.gif" alt="leaffive" style="position:absolute; left:100px; top:100px;" /> <img id="leaf6" src="images/leaf6.gif" alt="leafsix" style="position:absolute; left:100px; top:100px;" /> I have created an animation API, which has an option for the 'effect' or animation type. Now i'm trying to produce a slow, fast slow effect using a sine wave but seem to be having some trouble! The code below is supposed to get the steps to calculate each frame by diving the usable part of the sine wave into the total frames. The code should then go on to calculate insert the relevant values into the frame variables, after which multiply them all so that they are the correct scale so that when the animation is running it simply looks up the value and applies it, no need for any processing. With an animation from 0 to 740 (px in this case) the function returns: 115, 228, 335, 434, 523, 598, 659, 703, 730, 740 Oh and just a quick addition the variable "end" will equal 740 in the case above, or whatever the end value is. Code: case "SFS": var step = 90 / totalFrames; var pi = Math.PI; var raid = 0; for (var i = 1; i <= totalFrames; i++){ raid = (i*step)*(pi/180); queueFrameValue[topOfQueue][i] = Math.sin(raid); } var multiplier = end / queueFrameValue[topOfQueue][totalFrames]; for (var i = 1; i <= totalFrames; i++){ queueFrameValue[topOfQueue][i] = queueFrameValue[topOfQueue][i] * multiplier; } break; Thanks! Hi all, I'm new to Javascript, and having an issue with getInterval. For my programming languages class we have to create a simulation of waves breaking on a shore from above. I've decided to use a canvas object and Javascript for this animation, but am getting stuck on refreshing the frames. Here is the code I have so far: Code: var shoreline = new Array(); var waves = new Array(); var canWidth = 600; var canHeight = 400; var waveNum = 0; var count = 0; function wave() { setupShore(); var canvas = document.getElementById("canvas"); canvas.setAttribute("width",canWidth); canvas.setAttribute("height",canHeight); var ctx = canvas.getContext("2d"); createWave(); setInterval(update(ctx), 1000); } function update(ctx) { if(waves.length != 0) { drawWater(ctx); drawShore(ctx); drawWaves(ctx); updateWaves(); } } function drawElement(ctx, x, y, width, height, fillcolor) { ctx.fillStyle = fillcolor; ctx.fillRect(x, y, width, height); } function setupShore() { for(var i = 0; i <= canWidth/5; i++) { shoreline[i] = Math.round(canHeight/5); // + Math.floor(Math.random()*101); } } function createWave() { /* Wave array setup: [ [waveID1, [node1, node2, ..., nodeN]], [waveID2, [node1, node2, ..., nodeN] ] */ waves.push([waveNum, []]); for(var c = 0; c <= canWidth/5; c++){ waves[waves.length-1][1].push(canHeight); } waveNum = waveNum + 1; } function destroyWave() { waves.shift(); } function drawWater(ctx) { drawElement(ctx, 0, 0, canWidth, canHeight, "#336699"); } function drawShore(ctx) { for(var s = 0; s <= shoreline.length; s++) { drawElement(ctx, s*5, 0, 5, shoreline[s], "#FFCC00"); } } function updateWaves() { for(var u = 0; u < waves.length; u++) { var limit = waves[u][1].length; for(var v = 0; v < limit; v++){ var temp = waves[u][1][v]-5; waves[u][1][v] = temp; if(waves[u][1][v] <= shoreline[v]){ destroyWave(); } } } } function drawWaves(ctx) { for(var w = 0; w < waves.length; w++) { for(var n = 0; n <= waves[w][1].length; n++){ y = waves[w][1][n]; drawElement(ctx, n*5, y, 5, 5, "Purple"); } } } As you can see, the idea is that each 5-pixel wide node of the shore and wave are stored in arrays so that the position of each node can differ. The wave() function initializes all the required data, and then calls setInterval on update(). The function update() draws the water, shore, and wave, and then updates the wave position node-by-node. Ideally, setInterval would cause this to happen repeatedly, so that the wave would appear to move closer to the shore every 1000ms. However, this is not the case. It appears as though setInterval is working for one pass of update(), but fails after the first pass. You can tell that this is happening because the wave appears at its starting position, but does not continue to move. Any idea why this is happening? I read somewhere that setInterval can be broken by one-time functions, but I'm not sure. If you'd like to see what it's currently doing in a browser, I've hosted it here. Once I've got this animating properly I can continue my project, but I've hit a roadblock. Thanks in advance for your help, I'm really stuck. Marcus Hi guys. I'm trying this tutorial to get a sweet looking menu. http://snook.ca/archives/javascript/...ge-animations/ I've followed all the steps but I seem to be missing something, because the transition is just a simple hover transition. Can someone check what I'm doing wrong, please? Thank you very much! JS Code Code: $('a') .css( {backgroundPosition: "0 0"} ) .mouseover(function(){ $(this).stop().animate( {backgroundPosition:"(0 -150px)"}, {duration:500}) }) .mouseout(function(){ $(this).stop().animate( {backgroundPosition:"(0 0)"}, {duration:500}) }) HTML Code: Code: <!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> <link rel="stylesheet" type="text/css" href="styles.css" /> <script type="text/javascript" src="javascript.js"></script> <script type="text/javascript" src="jquery.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <ul> <li><a href="#">Home</a></li> <li><a href="#">About</a></li> <li><a href="#">Contact</a></li> </ul> </body> </html> Styles code Code: ul { list-style:none; margin:0; padding:0; } li { float:left; width:100px; height:50px; margin:0; padding:0; text-align:center; } li a { display:block; padding:0; height:100%; color:#FFF; text-decoration:none; } li a { background:url(animation.jpg) no-repeat 0 0; } li a:hover { background-position:0px -150px; } I'm attempting to write a function that will cause a small red dot to slide from off-screen, to it's position, 15 px into the page. However every time I run it, it does nothing, and I get a message on Firebug reading "dot 1 is null" on line 4 of the function. Below is the function: Code: function openingAnim() { var dot1 = null; dot1 = document.getElementById('m-dot1'); dot1.style.left = '0px'; doMove(); function doMove() { while (dot1.style.left < 15) { setTimeout("dot1.style.left = parseInt(dot1.style.left)+1+'px';",20); } } } And here is the id of the dot graphic from my CSS file: Code: #m-dot1 { position:absolute; background:url(../images/m-dot1.png); width:50px; height:50px; outline:none; left:-50px; top:89px; z-index:15 } Can anyone tell me what I'm doing wrong? I have just completed my JS studies and wish to try 3 things to test what I have learned, first I wish to create a simple animation, then I'll attempt my own slideshow and last a specific script. First, can I try the animation on this specific forum? If not then is there another forum for this on this board or do I have to go to an animation specific site please?
|