JavaScript - Sliding Puzzle Game
Please can anyone help?
hello I am novice when it comes to writing code and as i'm writing some code for a sliding puzzle game, i have managed to display the images. but now i need to write the functions to see if the image when clicked on is next to the blank one and then to move them if this is true. <Html> <Head> <Title> Sliding Puzzle Game</Title> <Script Language = "JavaScript"> var images = new Array(); //var initialise var id = 0; alert("starting"); window.onerror = handleError; function handleError(strMessage, strURL, intLine) //the above function catches any errors and display what and where. { document.write("<br/>The following Error occurred:"); document.write("<br/>Message: " + strMessage); document.write("<br/>Code: " + strURL); document.write("<br/>On line: " + intLine); } function Write2screen(){ var k=0; for (i=0; i< 4; i++) { for (j=0; j<4; j++) { id++; //give picture unique id after each iteration images[k] = "Images/" + k + ".jpg"; document.write(" <img src= '"+images[k]+"' id='"+id+"'/>"); k++; } document.write("<br/>"); } } function CanMoveTile() { // checks to see whether the cell at postion cellNum // is next to the black tile and returns true if and // only if this is the case } function moveTile(id) { // this function moves the tile that was clicked on (if the tile can actually be moved) } Write2screen(); </Script> </Head> <body onClick=moveTile(id)> </body> </Html> many thanks in advance Similar Tutorialshow to empty one of the cells and identify the adjacent cells (the ones with which the empty cell could swap on the first move.) Code: <script type="text/javascript"> <!-- var img_name = new Array("vinnpt1.jpg","vinnpt2.jpg","vinnpt3.jpg","vinnpt4.jpg","vinnpt5.jpg","vinnpt6.jpg","vinnpt7.jpg","vinnpt8.jpg"); img_name.sort(function() {return 0.5 - Math.random()}) document.write('<table border="1"><tbody>'); document.write('<tr>'); document.write('<td height="200" width="300">'); document.write('<img src ='+img_name[0]+'/>'); document.write('</td>'); document.write('<td height="200" width="300">'); document.write('<img src ='+img_name[1]+'/>'); document.write('</td>'); document.write('<td height="200" width="300">'); document.write('<img src ='+img_name[2]+'/>'); document.write('</td>'); document.write('</tr>'); document.write('<tr>'); document.write('<td height="200" width="300">'); document.write('<img src ='+img_name[3]+'/>'); document.write('</td>'); document.write('<td height="200" width="300">'); document.write('<img src ='+img_name[4]+'/>'); document.write('</td>'); document.write('<td height="200" width="300">'); document.write('<img src ='+img_name[5]+'/>'); document.write('</td>'); document.write('</tr>'); document.write('<tr>'); document.write('<td height="200" width="300">'); document.write('<img src ='+img_name[6]+'/>'); document.write('</td>'); document.write('<td height="200" width="300">'); document.write('<img src ='+img_name[7]+'/>'); document.write('</td>'); document.write('<td height="200" width="300">'); document.write('<img src ='+img_name[8]+'/>'); document.write('</td>'); document.write('</tr>'); document.write('</tbody></table>'); document.write('<table border="2"><tbody><tr><td height="50" width="452">Moves Used Goes Here</td><td height="50" width="452">Last Move Goes Here</td></tr></tbody></table>'); //--> </script> hi everyone. i have to create the 15 puzzle game and im having a difficult time getting started. can anyone help? i need to create a table (4x4) that has one empty space. All the other spaces must have a random generated value between 1 and 15. All i got so far is a onclick image swapping function.... need help! thanks
Hi there, I did a few basic tutorials etc, but I dont know if Im even on the right track I would like to make an image or "image button" based puzzle game, handling images and text but no animation, where you go to different Rooms to pick up pieces of the puzzle and put them in your inventory, or drop pieces of the puzzle from your inventory to the location you are in to achieve the puzzle objective. In a Nutshell: Display a grid of image buttons [2 x 3], pressing a button changes which buttons are displayed. The basic idea is to have buttons represent different places, where you can pickup or drop an item, and if you drop the right objects in the right place you win. Example: 2 top buttons [2 x 1] represent your inventory of 2 items (or empty slots), the 4 bottom buttons represent a 2x2 "map" with 4 "locations" buttons (to emulate locations on a map). You press a specific "location" and the 4 bottom buttons are replaced: the middle row is a "map" button to return to the map (with the 4 location buttons) and a "?" button to have a full screen text with info on the current location(which items to bring there) and an exit button to return. the bottom row are 2 items found in that location, and The 2 bottom items can be picked up, these items were randomly placed upon setup of the game, or dropped there by you, if you click on an item button at the bottom it highlights and you must click on a slot in your inventory at the top where the item (or nothingness) goes to replace what was there (item or empty slot). If you select an empty slot button at the bottom of a location and switch it with an item in your top inventory you effectively drop the item from your inventory to that specific location. Can this be done with javascript? Is it better to use HTML5? I would appreciate any help, advice, relevant tutorial link, or code snippet you can throw my way many thanks Ice Hi guys i am trying to make a sliding 15 puzzle in javascript. I have tried the code and I am able to scramble my board, however when I try to solve it some of my pieces go off the board on click and some even start to disappear on click. If anyone could help me with my for loop in my move function I would really appreciate it. I have posted my index and my game.js file which is my javascript i need help with. index.html Code: <?xml version="1.0" encoding="UTF-8"?> <!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> <title>Sliding Tiles</title> <style type="text/css"> h1 {position:absolute; left:100px; font-family:arial} p {position:absolute; left:100px; top:60px; color:red; font-family:arial; font-weight:bold} .board {position:absolute; left:100px; width:400px; top:100px; height:400px; background-color:black; border-style:none} div {position:absolute; width:94px; height:94px; background-color:aqua; border-style:solid; border-width:3px; text-align:center; font-family:century; font-weight:bold; font-size:60px} button {position:absolute; left:150px; width:300px; top:550px; height:50px; background-color:silver; font-family:arial; font-weight:bold; font-size:30px} </style> <script src="game.js" type="text/javascript"></script> </head> <body> <h1>Sliding Tiles <a href="http://validator.w3.org/check?uri=referer"> <img src="valid-xhtml10.gif" alt="Valid XHTML 1.0!" style="border:0;width:88px;height:31px" /></a></h1> <p>After starting a game, just click on the tile you'd like to move...</p> <div class="board" id="board"></div> <div id="tile1" style="left:100px; top:100px" onclick="move(1)"> 1 </div> <div id="tile2" style="left:200px; top:100px" onclick="move(2)"> 2 </div> <div id="tile3" style="left:300px; top:100px" onclick="move(3)"> 3 </div> <div id="tile4" style="left:400px; top:100px" onclick="move(4)"> 4 </div> <div id="tile5" style="left:100px; top:200px" onclick="move(5)"> 5 </div> <div id="tile6" style="left:200px; top:200px" onclick="move(6)"> 6 </div> <div id="tile7" style="left:300px; top:200px" onclick="move(7)"> 7 </div> <div id="tile8" style="left:400px; top:200px" onclick="move(8)"> 8 </div> <div id="tile9" style="left:100px; top:300px" onclick="move(9)"> 9 </div> <div id="tile10" style="left:200px; top:300px" onclick="move(10)"> 10 </div> <div id="tile11" style="left:300px; top:300px" onclick="move(11)"> 11 </div> <div id="tile12" style="left:400px; top:300px" onclick="move(12)"> 12 </div> <div id="tile13" style="left:100px; top:400px" onclick="move(13)"> 13 </div> <div id="tile14" style="left:200px; top:400px" onclick="move(14)"> 14 </div> <div id="tile15" style="left:300px; top:400px" onclick="move(15)"> 15 </div> <form action=""> <button onclick="initialize(); return false">Start a New Game</button> </form> </body> </html> game.js Code: var rows = new Array(4) rows[0] = new Array (4) rows[1] = new Array (4) rows[2] = new Array (4) rows[3] = new Array (4) function checkWin() { var winner = false var checker = new Array(4) checker[0] = new Array (1, 2, 3, 4) checker[1] = new Array (5, 6, 7, 8) checker[2] = new Array (9, 10, 11, 12) checker[3] = new Array (13, 14, 15, 0) for (i = 0; i < 4; i++){ for (j = 0; j < 4; j++){ if (rows[i][j] == checker[i][j]){ winner = false } } } if (winner){ alert("Congratulations! You've Won!") return true } return false } function move(tile){ var obj = document.getElementById('tile' + tile) var win = false for (i = 0; i < 4; i++){ for (j = 0; j < 4; j++){ if (rows[i][j] == tile){ if (j > 0 && rows[i][j - 1] == 0){ obj.style.left = (j - 2) * 100 + 'px' rows[i][j - 1] = tile rows[i][j] = 0 }else if (j < 3 && rows[i][j + 1] == 0){ obj.style.left = (j + 2) * 100 + 'px' rows[i][j + 1] = tile rows[i][j] = 0 }else if (i > 0 && rows[i - 1][j] == 0){ obj.style.top = (i - 2) * 100 + 'px' rows[i - 1][j] = tile rows[i][j] = 0 }else if (i < 3 && rows[i + 1][j] == 0){ obj.style.top = (i + 2) * 100 + 'px' rows[i + 1][j] = tile rows[i][j] = 0 } win = checkWin() if (win){ break } return } } } } function initialize(){ var check = new Array (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) for (i = 0; i < 4; i++) { for (j = 0; j < 4; j++) { if (i == 3 && j == 3){ rows[i][j] = 0 } else { var n = Math.ceil(Math.random() * 15) while (check[n - 1] == 0){ n = Math.ceil(Math.random() * 15) } rows[i][j] = n check[n - 1] = 0 document.getElementById('tile' + n).style.left = (j + 1) * 100 + 'px' document.getElementById('tile' + n).style.top = (i + 1) * 100 + 'px' } } } } trying to make a very simple scrambler for a 15 puzzle, i just cant doanything to comlicated. here is my table. <table border="1" " cellpadding="50" align="center"> <tr> <td ><input type="button" id="1" value="1" onclick=" swap1(id);"></td> <td > <input type="button" id="2" value="2" onclick="swap2(id)"></td> <td> <input type="button" id="3" value="3" onclick="swap3(id)"> </td> <td> <input type="button" id="4" value="4" onclick="swap4(id)"> </td> </tr> <tr> <td> <input type="button" id="5" value="5" onclick="swap5(id)"> </td> <td> <input type="button" id="6" value="6" onclick="swap6(id)"> </td> <td> <input type="button" id="7" value="7" onclick="swap7(id)"> </td> <td> <input type="button" id="8" value="8" onclick="swap8(id)"> </td> </tr> <tr> <td> <input type="button" id="9" value="9" onclick="swap9(id)"> </td> <td> <input type="button" id="10" value="10" onclick="swap10(id)"> </td> <td> <input type="button" id="11" value="11" onclick="swap11(id)"> </td> <td> <input type="button" id="12" value="12" onclick="swap12(id)"> </td> </tr> <tr> <td> <input type="button" id="13" value="13" onclick="swap13(id)"> </td> <td> <input type="button" id="14" value="14" onclick="swap14(id)"> </td> <td> <input type="button" id="15" value="15" onclick="swap15(id)"> </td> <td> <input type="button" id="16" value="" onclick="swap16(id)"> </td> </tr> </table> <p align="center"><input type="button" id="scramble" value="Scramble" onclick="random(id)"></p> <br> This is a code I wrote about a javascript game which you should click on each picture so that the puzzle will be done. I have nine pictures with each picture named 1.jpg 2.jpg --- 9.jpg I have three difficulties beginner intermediate hard . The code has logical errors I can't understand . can anybody help me <html> <head> <title> CAIS326 Assignment 3 </title> <script type="text/javascript"> <!-- var seconds = 0; var timerId; var time; var Click1 = 0,Click2 = 0,Click3 = 0,Click4 = 0,Click5 = 0,Click6 = 0,Click7 = 0,Click8 = 0,Click9 = 0; var Pictures = [1,2,3,4,5,6,7,8,9]; function SwapImages() { for(var q=0 ; q<9; q++) document.getElementById("image+q+").src = Pictures[Click+q+ -1]+".jpg"; } function RegisterClicks(Index) { if (Click1 == 0) Click1 = Index; else if (Click2 == 0) Click2 = Index; else if (Click3 == 0) Click3 = Index; else if (Click4 == 0) Click4 = Index; else if (Click5 == 0) Click5 = Index; else if (Click6 == 0) Click6 = Index; else if (Click7 == 0) Click7 = Index; else if (Click8 == 0) Click8 = Index; else if (Click9 == 0) Click9 = Index; for(var m=0; m<9; m++) { if (Click+m+ > 0 && Click+m + 1+ > 0){ SwapImages(); Click+m+ = 0; Click+m + 1+ = 0; } } } function startTimer() { if (document.form1.gamelevel[0].checked) time=60; else if (document.form1.gamelevel[1].checked) time=45; else time=30; // 1000 milliseconds = 1 second timerId = window.setInterval( "updateTime()", 1000 ); } function updateTime() { seconds++; soFar.innerText = seconds; if ( time == seconds) { seconds = 0; window.alert ("Game over Loser..."); clearTimeout(timerId); } } var array = new Array(9); for (var i=0; i<9; i++) { array[i] = i+1; } shuffle(); document.writeln("<table border=1>"); var b = 0; while (b < 9 ) { var num = array[b]; document.writeln("<tr><td><img src=\""+num+".jpg\" id =\"image"+num+" \" onClick=\"RegisterClicks("+num+")\" /></td>"); ++b; num = array[b]; document.writeln("<td><img src=\""+num+".jpg\" id =\"image"+num+" \" onClick=\"RegisterClicks("+num+")\" /></td>"); ++b; num = array[b]; document.writeln("<td><img src=\""+num+".jpg\" id =\"image"+num+" \" onClick=\"RegisterClicks("+num+")\" /></td></tr>"); ++b; } document.writeln("</table>"); function shuffle() { var k = 9; var RandNum; var Temp; for (var n=0; n<9; n++) { RandNum = Math.floor(Math.random()*k); Temp = array[k-1]; array[k-1] = array[RandNum]; array[RandNum] = Temp; k=k-1; } } //--> </script> </head> <body> <form name = "form1" action = ""> <input type="Radio" name = "gamelevel" Value = "Beginner" Checked = "true" /> <font color=#37448E>Beginner</font> <input type="Radio" name = "gamelevel" Value = "Intermediate" /> <font color=#37448E>Intermediate</font> <input type="Radio" name = "gamelevel" Value = "Advanced" /> <font color=#37448E>Advanced</font></div><br/><br/> <input type = "button" value = " start " onClick="startTimer()"/><br/> <p>Seconds you have spent viewing this page so far: <strong id = "soFar">0</strong></p> </form> </body> </html> Does anyone know how to make these things work? I have to make this hanjie puzzle and I have at least gotten the black squares to display. I have worked through all the directions three times and run it through the Firebug. I don't understand what it is asking for and don't know how to change the code to make this work, someone please help me! Code: window.onload = setPuzzle; var allCells = new Array(); function setPuzzle() { var puzzleTable = document.getElementById("puzzleCells"); allCells = document.getElementsByTagName("td"); for (var i =0; i < allCells.length; i++) { allCells[i].style.backgroundColor = "white"; allCells[i].onclick = changeColor; } document.getElementById("solution").onclick = showSolution; document.getElementById("hide").onclick = hideSolution; document.getElementById("solution").onclick = showSolution; document.getElementById("check").onclick = checkSolution; document.getElementById("uncheck").onclick = uncheckSolution; } function changeColor(){ this.style.backgroundColor = (this.style.backgroundColor == "black") ? "white" : "black"; } function showSolution(){ for(var i=0;i<allCells.length; i++) { if(allCells.className == "dark"){ allCells[i].style.backgroundColor = "black"; } else { allCells[i].style.backgroundColor = "white"; } } checkCount = 0; } function hideSolution() { for(var i=0;i<allCells.length; i++) { allCells[i].style.backgroundColor = "white"; } checkCount = " "; } function checkSolution() { var checkCount = 0; for (var i = 0; i< allCells.length; i++) { if (allCells[i].style.backgroundColor == "black" && allCells[i].className != "dark") { allCells[i].style.backgroundColor = "red"; } else if (allCells[i].className == "dark" && allCells[i].style.backgroundColor == "white"){ checkCount++; } return checkCount.value; } } function uncheckSolution() { for (var i = 0; i< allCells.length; i++) { if (allCells[i].style.backgroundColor == "red") { allCells[i].style.backgroundColor = "black"; } checkCount = " "; } } I need to make a --very-- simple version of this game: http://javascript.internet.com/games/magic-squares.html. You need to click on the buttons until they're in order, then you win. I'm having trouble with the function that trades the places of the two buttons. So, can anyone tell me how my "swap" function should be? It needs to test if the value of the button next to the button clicked on is blank, and then if it is, the two values trade places. This way, I will hopefully end up with 9 different functions, depending on which square I'm clicking on, because the "id" of the button stays the same, it just swaps the values. It shouldn't use any arrays or anything. Thanks, I appreciate the help! Here's what I have so far: Code: <html> <head> <title>15 Puzzle</title> <script type="text/javascript"> function swap(id){ if(document.getElementById(id+1).value="") { document.getElementById(id+1).value=document.getElementById(id).value; document.getElementById(id).value=""; alert('It works!'); } } </script> </head> <p><h1 align="center">15 Puzzle</h1><p> <p align="center"><input type="button" id="scramble" value="Scramble"></p> <br> <table border="3" bordercolor="black" width="300" bgcolor="" cellpadding="50" align="center"> <tr> <td ><input type="button" id="1" value="1" onclick=" swap(this.id);"></td> <td > <input type="button" id="2" value="" onclick="swap(this.id)"></td> <td> <input type="button" id="3" value="3" onclick="swap(this.id)"> </td> <td> <input type="button" id="4" value="4" onclick="swap(this.id)"> </td> </tr> <tr> <td> <input type="button" id="5" value="5" onclick="swap(this.id)"> </td> <td> <input type="button" id="6" value="6" onclick="swap(this.id)"> </td> <td> <input type="button" id="7" value="7" onclick="swap(this.id)"> </td> <td> <input type="button" id="8" value="8" onclick="swap(this.id)"> </td> </tr> <tr> <td> <input type="button" id="9" value="9" onclick="swap(this.id)"> </td> <td> <input type="button" id="10" value="10" onclick="swap(this.id)"> </td> <td> <input type="button" id="11" value="11" onclick="swap(this.id)"> </td> <td> <input type="button" id="12" value="12" onclick="swap(this.id)"> </td> </tr> <tr> <td> <input type="button" id="13" value="13" onclick="swap(this.id)"> </td> <td> <input type="button" id="14" value="14" onclick="swap(this.id)"> </td> <td> <input type="button" id="15" value="15" onclick="swap(this.id)"> </td> <td> <input type="button" id="16" value="2" onclick="swap(this.id)"> </td> </tr> </table> </html> This is a simple basic game i want to make. Its a "What Am I" Riddle... The questions is (In HTML which i already know): I'm as light as a feather but no man can hold me for long. What am I? the answer is: Your Breath. (This is where the JAVASCRIPT comes in) Lets say they guess a rock, have a pop up say: Wrong Answer. Please try again. Lets say they guess Your breath -OR- Breath, have a pop up say: Correct! I want a text field where you can enter your answer, and if they choose ANYTHING but the 2 correct answers above, it will display please try again. Can anyone code this please? Thanks for reading. Ok so i want to work on an EASY basic game. As simple as Guess what number... But there are some twist... Ok So here is my example... (HTML, i know this.)I'm Guessing a number 1-99. What is it? (java) Lets say its 66 and they guess 53, have the text rusult be in a pop up window be: Too low! (java) Lets say they guess 78, have the text rusult be in a pop up window be: Too high! (java) Lets say they guess 100+, have the text rusult be in a pop up window be: Out of range! (java)But lets say they guess 66, have a text result be in a pop up window be: You've won! (java) I want a text field where you can enter your answer, and it will do the actions above. Can anyone code this? Thanks for reading! I have a slider that slides the content from the top to bottom when a link/button is clicked. I want it to slide out from the right side of the button and move left to right. Is this possible by just adjusting the code I already have? Thanks. HTML: 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> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>jQuery Accordion Style DIV Menu</title> <link href="format.css" rel="stylesheet" type="text/css" /> <link href="text.css" rel="stylesheet" type="text/css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script> <script type="text/javascript" src="javascript.js"> </script> </head> <body> <div id="wrapper"> <div class="accordionButton">Button 1 Content</div> <div class="accordionContent">Content 1<br /><br /><br /><br /><br /><br /><br /><br />Long Example</div> <div class="accordionButton">Button 2 Content</div> <div class="accordionContent">Content 2<br /><br /><br /><br /><br />Medium Example</div> <div class="accordionButton">Button 3 Content</div> <div class="accordionContent">Content 1<br />Short Example</div> <div class="accordionButton">Button 4 Content</div> <div class="accordionContent">Content 4<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />Extra Long Example</div> </div> </body> </html> javascript.js: Code: $(document).ready(function() { //ACCORDION BUTTON ACTION (ON CLICK DO THE FOLLOWING) $('.accordionButton').click(function() { //REMOVE THE ON CLASS FROM ALL BUTTONS $('.accordionButton').removeClass('on'); //NO MATTER WHAT WE CLOSE ALL OPEN SLIDES $('.accordionContent').slideUp('normal'); //IF THE NEXT SLIDE WASN'T OPEN THEN OPEN IT if($(this).next().is(':hidden') == true) { //ADD THE ON CLASS TO THE BUTTON $(this).addClass('on'); //OPEN THE SLIDE $(this).next().slideDown('normal'); } }); /*** REMOVE IF MOUSEOVER IS NOT REQUIRED ***/ //ADDS THE .OVER CLASS FROM THE STYLESHEET ON MOUSEOVER $('.accordionButton').mouseover(function() { $(this).addClass('over'); //ON MOUSEOUT REMOVE THE OVER CLASS }).mouseout(function() { $(this).removeClass('over'); }); /*** END REMOVE IF MOUSEOVER IS NOT REQUIRED ***/ /******************************************************************************************************************** CLOSES ALL S ON PAGE LOAD ********************************************************************************************************************/ $('.accordionContent').hide(); }); Hi, I was wondering if someone could help me out by providing me with the code which allows the chart to slide on (click on Report a Link , right next to the search box): http://www.watchseries-online.com/20...x9-improv.html I need to imporove the way this functions on my site. Here is how the report a link functions on my site: 1. go to http://tehcake.com/video/Simpsons/6x9 Look right below the video and right above the chatbox " Report Broken Episode/ Problem " if you click on the link, it takes you to another pages where the form is located. I would like to change it so that when a user clicks on " Report Broken Episode/ Problem ", then it simply relveals a sliding down chart that operates like the one found at http://www.watchseries-online.com/20...x9-improv.html (where it says : [!] REPORT A LINK in red text, to the left of the searchbox click on that, then click submit. It is not only better looking but also submits without even leaving the page) I virtually know no javascript, but have been trying to create some sliding menus. 4 Menus along the bottom of the screen that on mouse over, a sub menu slides up from them. I managed to get them to work to slide up, but then when I put the code in to slide back down again it started spazzing out! Can anyone help at all? Here's my javascript code. Code: <script type="text/javascript"> var curVisible; var oldObject; var pusher; var pushBack; var inMotion = false; function reveal(obj) { if(curVisible != null) { oldObject = curVisible; } if(!inMotion) { curVisible = obj; pusher = -100; pushBack = 40; document.getElementById(obj).style.visibility = "visible"; document.getElementById(obj).style.bottom = pusher+"px"; animateOut(); animateIn(); } } function hide() { animateIn(); } function animateIn() { if (pushBack > -100) { inMotion = true; pushBack -=4; document.getElementById(oldObject).style.bottom = pushBack+"px"; setTimeout(animateIn, 20); } else { document.getElementById(oldObject).style.visibility = "hidden"; inMotion = false; } } function animateOut() { if(pusher < 40) { inMotion = true; pusher += 4; document.getElementById(curVisible).style.bottom = pusher+"px"; setTimeout(animateOut, 20); } else { inMotion = false; } } </script> Thanks very much. Have tried loads, but just can't seem to get it to work. It's a lot more complicated than I first thought. Dave I'm trying to make this menu go up and down when the arrows are clicked. Right now, it shows all of them and I can't figure out how to make it so that it only shows the first 9 and will show the rest in the menu when it's clicked. I really don't know where to start. I found some scripts but they turned out really funky. Even if it's something super simple is cool, just where to begin?? Here is the menu: Code: <div class="arrow_holder"><span onclick="document.getElementById('down').display = 'none'; document.getElementById('up').display = 'block';" ><img src="images/arrow-up.png" alt="" border="0" /></span></div> //video1 <div class="portfolio_details" onclick="change_video(1);"> <div class="work_thumb"><img src="images/12.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>12 FL OZ</strong><br />Narrative / Television</a></div> </div> //video2 <div class="portfolio_details" onclick="change_video(2);"> <div class="work_thumb"><img src="images/catch.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>THE CATCH: COSTA RICA</strong><br />Narrative / Television</a></div> </div> //video3 <div class="portfolio_details" onclick="change_video(3);"> <div class="work_thumb"><img src="images/cole.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>COLE PETTICOAT P.I.</strong><br />Narrative / Television</a></div> </div> //video4 <div class="portfolio_details" onclick="change_video(4);"> <div class="work_thumb"><img src="images/mayan_thumb.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>MAYAN BLUE</strong><br />Documentary</a></div> </div> //video5 <div class="portfolio_details" onclick="change_video(5);"> <div class="work_thumb"><img src="images/marine.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>MARINE INVESTIGATORS</strong><br />Documentary</a></div> </div> //video6 <div class="portfolio_details" onclick="change_video(6);"> <div class="work_thumb"><img src="images/police.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>DISH POLICE</strong><br />Commercial</a></div> </div> //video7 <div class="portfolio_details" onclick="change_video(7);"> <div class="work_thumb"><img src="images/septic.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>SUPER SEPTIC MIKE ROBE</strong><br />Commercial</a></div> </div> //video8 <div class="portfolio_details" onclick="change_video(8);"> <div class="work_thumb"><img src="images/adultswim.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>ADULT SWIM - HAIKU</strong><br />Commercial</a></div> </div> //video9 <div class="portfolio_details" onclick="change_video(9);"> <div class="work_thumb"><img src="images/miller.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>MILLER LITE / FALCONS</strong><br />Commercial</a></div> </div> //video10 <div class="portfolio_details" onclick="change_video(10);"> <div class="work_thumb"><img src="images/trulite.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>TRUCLEAR HD PLUS</strong><br />Commercial</a></div> </div> //video11 <div class="portfolio_details" onclick="change_video(11);"> <div class="work_thumb"><img src="images/tara.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>TARA JEWELRY</strong><br />Commercial</a></div> </div> //video12 <div class="portfolio_details" onclick="change_video(12);"> <div class="work_thumb"><img src="images/boomerang.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>BOOMERANG VAMPIRES</strong><br />Commercial</a></div> </div> video13 <div class="portfolio_details" onclick="change_video(13);"> <div class="work_thumb"><img src="images/gapower.jpg" alt="" border="0" /></div> <div class="work_name"><a href="#"><strong>GA POWER FALCONS</strong><br />Commercial</a></div> </div> <div class="arrow_holder"><span onclick="document.getElementById('up').display = 'none'; document.getElementById('down').display = 'block';" ><img src="images/arrow-down.png" alt="" border="0" /></span></div> </div> Hello I am fairly new to Javascript and found this code online but can't seem to get it to work right. here is the code I am using it is suppose to apply a style attribute the the id "toplink" but I can't seem to get it to work right. Code: $(document).ready(function(){ menuYloc = parseInt($(name).css("top").substring(0,$(name).css("top").indexOf("px"))) $(window).scroll(function () { var offset = menuYloc+$(document).scrollTop()+"px"; $("#toplink").animate({top:offset},{duration:500,queue:false}); }); }); Thanks in advance So about a couple of weeks ago I decided to start learning the basics of web development and design through the w3schools website. I found no problems learning HTML/XHTML and CSS1/2/3. I decided the best way to learn these languages was to implement something from each language into a project (a website, which is currently stored locally on my laptop) The project is a site dedicated to favourite images of my family. In it is a main image viewer, followed by a nav bar underneath displaying thumbnails of a few images. I implemented a small JS script so when I click a thumbnail, the corresponding image is displayed within the main image viewer. I then moved onto jQuery in my development knowledge quest, and decided the next thing I wanted to do was add more images to the nav bar and be able to scroll (with two buttons) across the nav bar. This is where I've hit an end stop in being able to do this with no help. So to begin with, this is my HTML for the thumbnail navbar: Code: <div class="scrollWrapper"> <div class="controlsPrev"></div> <div class="controlsNext"></div> <div class="scrollableArea"> <p><input type="image" src="images/home/54.jpg" alt="Image" onclick="displayImage('images/home/54.jpg')" /></p> <p><input type="image" src="images/home/55.jpg" alt="Image" onclick="displayImage('images/home/55.jpg')" /></p> <p><input type="image" src="images/home/56.jpg" alt="Image" onclick="displayImage('images/home/56.jpg')" /></p> <p><input type="image" src="images/home/57.jpg" alt="Image" onclick="displayImage('images/home/57.jpg')" /></p> <p><input type="image" src="images/home/58.jpg" alt="Image" onclick="displayImage('images/home/58.jpg')" /></p> <p><input type="image" src="images/home/59.jpg" alt="Image" onclick="displayImage('images/home/59.jpg')" /></p> <p><input type="image" src="images/home/60.jpg" alt="Image" onclick="displayImage('images/home/60.jpg')" /></p> <p><input type="image" src="images/home/61.jpg" alt="Image" onclick="displayImage('images/home/61.jpg')" /></p> <p><input type="image" src="images/home/62.jpg" alt="Image" onclick="displayImage('images/home/62.jpg')" /></p> <p><input type="image" src="images/home/63.jpg" alt="Image" onclick="displayImage('images/home/63.jpg')" /></p> </div> </div> </div> CSS Styling (external sheet): Code: div.scrollWrapper { background-color:#252525; width:960px; height:115px; display:block; overflow:hidden; } div.scrollableArea { height:115px; } div.scrollableArea p { margin:0; } div.controlsPrev { height:115px; width:65px; background-color:#FFFFFF; position:absolute; } div.controlsNext { height:115px; width:65px; background-color:#FFFFFF; position:absolute; right:195px; } My first problem is that now I have added further <p> elements to the navbar, they "wrap" to the next line, causing scrollableArea to be double the height. The second problem is implementing some code to bring the navbar to life. Since it's jQuery (and I've linked the googleapis library in my html document) I thought the custom animation methods would be the best way to create this effect. Though I've thought of a few obstacles in my way, namely: 1. How to hide the right most or left most (depending on which control class eg. Prev or Next) <p> element and show the opposite <p> element at the same time, and also shift or slide all other <p> elements in view across (again depending on which control class or direction control I have clicked). 2. I want flexible code, that allows for (in the future) more <p> elements. All my code has been based around flexibility and the fact that it will be constantly changing at a fast rate. Therefore I think a function within my script to count the number of <p> elements within the scrollableArea would resolve this issue somewhat. Any help or advice given on the subject would be greatly appreciated, if there would be another method to get the desired effect then please share. I've stayed away from plug-ins apart from the generic jQuery library provided by google, I want to be able to say I have created everything by myself and not "cheated" if you will. It doesn't take a genius to implement plug-ins into code, I see it on various websites and have seen developers use them before and claim them as their own. I took a look at a few tutorials on the subject, but I haven't found anything specific to my cause. Cheers dudes, Johnny. Hi all, I am new to this forum and still fairly new to website design and coding. My girlfriend is a fashion designer and I said I would build her a website (one of those things I said whilst watching the football). I am trying to find if a script exists to have an image slide-show which moves to the right when the cursor moves to the right and so on for the left. We have managed to find someone else who has done exactly what she wants but it's in flash and I have no experience at all in flash. So I was wondering if anyone knows of a script which does the exact same thing? Below is the link to the site where they have managed to do what we are looking for in Flash: http://www.matthewwilliamson.com/collections.php Any help would be greatly appreciated. Cheers guys Hi, I'm relatively new to javascript, I am trying to create a sliding menu, everything is working fine other than the hyperlinks are not working, they open if you right click and select open link, but not with a normal click. Any help will be very appreciated, you can acsess the javascript he http://justifi.co.uk/menu.js the css he http://justifi.co.uk/menu.css and the html he http://justifi.co.uk/menu.html Thank you in advance; James Hello. I've created this sliding panel where I click the Sidebar button and it slides out or in. But I would like to make it run more smoothly. I tried storing references to the elements within the MoveSidebar() as this.variables, so that they wouldn't be re-defined each time, but then FF spits out that 'this.sidebar.style' is undefined?! How can I make it run more smoothly, or get FF to recognise 'this.sidebar.style' please (once I reinstate all the this.references)? Here's the whole page and the button is also attached for ease of testing. Andy. Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Sidebar Panel</title> <style type="text/css"> #sidebar { display: inline-block; position: fixed; top: 200px; right: -100px; } #sidebar img { cursor: pointer; } #sidebar ul { display: inline-block; list-style-type: none; padding: 0; margin: 0; background: lightgrey; margin-left: -4px; height: 97px; /* same as the image */ } #sidebar li { display: inline; } #sidebar a { float: left; clear: left; width: 90px; text-decoration: none; padding: 2px 5px; } </style> <script type="text/javascript"> var theTimer; function MoveSidebar() { var sidebar = document.getElementById('sidebar'); var sideRight = parseInt(sidebar.style.right || "-100px"); var out = document.getElementById('sideImage').out; if ( out && sideRight <= 0 ) { sidebar.style.right = (sideRight + 2) + 'px'; } else if ( !out && sideRight >= -100 ) { sidebar.style.right = (sideRight - 2) + 'px'; } else { clearInterval(theTimer); } } function InitSide() { document.getElementById('sideImage').onclick = function () { this.out = ( this.out ) ? false : true; clearInterval(theTimer); theTimer = setInterval(MoveSidebar,10); } } window.onload = InitSide; </script> </head> <body> <h1>Creating a Sidebar Panel Button</h1> <div id="sidebar"> <img src="images/sidebar.png" id="sideImage"> <ul> <li><a href="#home">Home</a></li> <li><a href="#about">About</a></li> <li><a href="#further">Further Info</a></li> <li><a href="#contact">Contact Us</a></li> </ul> </div> </body> </html> |