Jump to content

Ingolme

Moderator
  • Posts

    14,901
  • Joined

  • Last visited

  • Days Won

    177

Everything posted by Ingolme

  1. It's not possible in CSS. When you select span.paren:hover, you're selecting all spans with class "paren" There's no selector that can select an element based on what other elements it contains, which is what would be necessary to make this possible in CSS.
  2. Ingolme

    Error in Google

    The CSS means nothing without an HTML context to apply it to. That's also a whole lot of CSS to look through. Which are the rules that are targeting the element that's misplaced? It looks like you're using absolute or relative positioning somewhere, something that you shouldn't have to do.
  3. This is bootstrap's documentation: http://getbootstrap.com/css/#grid-options A small device is between 768 and 991 pixels wide. A medium device is between 992 and 1199 pixels. A large device is anything wider than 1200 pixels wide. Anything under 768 is extra small. Add this to your page to see if your smartphone is really as high a resolution as you think: <script> alert("Screen width: " + screen.width + "nWindow width: " + window.innerWidth);</script>
  4. Are you calling AddBook more than once? IDs have to be unique, there cannot be more than one of each ID. If there is, then the browser will not behave properly. Also, why can't you just write the HTML right onto the page instead of having Javascript do it?
  5. Bootstrap uses media queries. The arrangement of the columns depends only on the width of the browser window, not of the device. If you have a large screen but your browser window isn't maximized it may adopt the arrangement that was set for small or medium screens depending on how wide the window is.
  6. An inline element cannot have a width, height, padding or margins. It only occupies as much horizontal space as the content that's within it, it only occupies as much vertical space on each line as the line-height CSS property tells it to. It really makes no sense to put a block inside an inline element. The block will behave nearly as if the inline element didn't exist.
  7. Can you show the responseText? Something is wrong with the syntax if JSON.parse() is failing.
  8. A function is "stored" somewhere. There are two things you can do with that function: Give a reference to where it is stored, or to call the function. To give a reference to the function, you write its name, to call it, you write its name and add the parentheses (). When you call the function it will run exactly the moment you call it. If what you want is to have the function called later, you need to just give a reference and not call it right on the spot. Here's the difference between a reference and calling the function: function five() { return 5;}// This is a reference to the functionvar a = five;// On this line we call the function and save the result in the variablevar b = five(); // B is now "5"// We can also call the function by its reference:var c = a(); // C is now "5 setTimeout() and setInterval() can take one of two things as their first parameter: 1. A string of code2. A reference to a function function showResult() { var n = 5 + 3; alert(n);}// Executing a string of code:setTimeout("var n = 5 + 3; alert(n)", 5000);// Running a function:setTimeout(showResult, 5000); Executing a string of code is a bad idea because the browser has to run Javascript's parsing engine over again to turn that string into real code which makes the browser do a lot more work. The Javascript tutorial assumes you're writing in HTML 5, but your current document is not HTML 5, it's being interpreted as an old version of HTML which required the type attribute. You need to choose a version of HTML by putting the right <!DOCTYPE> declaration at the beginning of your code. It's important than your page is valid HTML so that Javascript and CSS will work as they should. You should read the HTML tutorial: http://www.w3schools.com/html/html_basic.asp
  9. Certain security features might be preventing Google Chrome from using some image resources. When a canvas is drawn on by an image loaded from another website it is considered tainted and its image data cannot be used to draw on another canvas. Chrome possibly applies this restriction to files loaded locally from the computer as well. Are you sure no error messages are showing up on the console?
  10. Both of your questions were answered previously. First, you use substr() to get the first few letters, then convert them all to lower case using strtolower(). Then you use the switch-case construct to decide what to do with the resulting value.
  11. Yes, you should begin using the new semantic HTML elements. For Internet Explorer 8 and under to style them properly you'll need what's called a "shiv". What it does is call document.createElement() for each of the kinds of elements that Internet Explorer doesn't understand and then gives default styles for them.
  12. When it comes to how it appears to the average user, yes, it looks the same. Screen readers might interpret them differently.
  13. They're there so that future technology can understand what's contained in them. For example, a search engine might choose to ignore content in the topmost header and footer elements when indexing content from a particular page so that the search result more accurately reflects the page itself. IDs can't be used like this because there's no standardized convention for which ID means what.
  14. Attributes don't go between tags, they go inside tags. Empty elements have still one tag inside which you can put attributes. Attributes are not content. Content is what goes between the tags.
  15. It sounds like $_POST['submit'] isn't set, so the query isn't being executed. You should put your code in a [CODE][/code] tags so we can see it properly. Here's what your code looks like: <?phpif (isset($_POST['submit'])) { $name = $_POST['name']; $host ="localhost"; $username = "username"; $password = "password"; $dbname = "database"; $con = mysql_connect($host, $username, $password, $dbname); //Check Connection if (!$con) { die("Could not connect: " . mysql_error()); } //Select your database mysql_select_db("database",$con); //Check to make sure the database is there if (!$mysql_select_db) { die ('Can't use the db : ' . mysql_error()); } //Run query $insert = mysql_query("insert into Users(name) values ('$name')");}// This section of code runs regardless of whether $_POST['submit'] exists or not//Check Queryif (!$insert) { die("lid query: " . mysql_error());}echo "Data inserted";mysql_close($con);?>
  16. Once you already have the screen coordinate, in the part of the program that draws the sprite, just check the Y coordinate on the screen to determine whether you should draw something or not. if(screen.y > canvas.height*0.5) { // If the position on the screen is further down than half of the canvas height // Draw the sprite // ...
  17. Well, what does the error say? You're printing an error message for a reason, the error message helps to figure out why something isn't working. Your code is vulnerable to SQL injection, making your site really easy to hack. You should do two things: 1. Don't use the mysql library because it's vulnerable to security threats, change to mysqli or PDO. 2. Learn prepared statements to ensure without a doubt that you won't have problems with SQL injection.
  18. Here's Facebook's documentation for comments widgets, like buttons and other features you can embed on your site: https://developers.facebook.com/docs/plugins Here's twitter's documentation: https://dev.twitter.com/web/overview Documentation for Google+ widgets and buttons: https://developers.google.com/+/web/share/ https://developers.google.com/+/web/+1button/ https://developers.google.com/+/web/
  19. If you're getting a PHP error, show the entire contents of the PHP file so we can see where it is. It's probably a simple mistake like a missing semi-colon. If you're getting a Javascript error, for debugging you can check the value of xmlhttp.responseText without parsing it. try { var data = JSON.parse(xmlhttp.responseText);} catch(e) { // If it' not working, debug by checking the responseText alert(xmlhttp.responseText);}
  20. HTML 5 allows the omission of the <html>, <head> and <body> tags, but I don't recommend it. http://www.w3schools.com/html/html5_syntax.asp The problem with your parallax program is not making a distinction between real coordinates and screen coordinates. Each sprite should have the following properties: image: The image you show on the screen to represent the sprite x, y: Its world coordinates vx, vy: Its velocity depth: Important for parallax, a coefficient to determine how fast or slow to make it move. Depth is 1 for elements in the foreground, you can use 0.5 for the background, but any value between0 and 1 works. width, height: For this purpose, it's the same as what you called sourceWidth and sourceHeight earlier but also represents the sprite's size in the actual world sourceX, sourceY: This is where to start slicing on the sprite's source image Here's how your logic should go in each animation frame: 1. Update velocities of all objects 2. Update positions of everything on the world based on their own velocity 3. Update the position of the camera 3.5 (optional) Get screen coordinates and use them to update object's position 4. Get screen coordinates of the objects to draw them. So here's the main idea. First you get the real world coordinates // Calculate velocities// for each sprite:sprite.vx = 5; // Arbitrary value 5 for this examplesprite.vy = 5; // Arbitrary value 5 for this example// Update positions// For each sprite:sprite.x += sprite.vx;sprite.y += sprite.vy;// Update the camera// This example has the camera always pointing at the catcamera.x = cat.x;camery.y = cat.y; Now you can find out the screen coordinates using the following formula: function getScreenCoordinates(sprite) { /* We can determine the X and Y position on the screen without having to modify the sprite's actual X and Y positions */ var screenX; var screenY; // The following formula is used to find the screen position of the object // 1. Get the position on the screen by subtracting the camera's position from it screenX = sprite.x - camera.x; screenY = sprite.y - camera.y; // 2. Multiply by the depth coefficient for parallax screenX *= depth; screenY *= depth; // 3. Make sure the camera is pointing at the center of the canvas instead of the top // left corner by adding half the canvas width and height screenX += canvas.width * 0.5; screenY += canvas.height * 0.5; // 4. The sprite is currently positioned by its top left corner, let's make it based // on the center of the sprite: screenX -= sprite.width * 0.5; screenY -= sprite.height * 0.5; return { x : screenX, y : screenY }} Now you can find out when the sprite is in the upper half of the screen and move it to the bottom again like this: var screen = getScreenCoordinates(sprite);if(screen.y < canvas.height * 0.5) { // This formula moves the sprite to the bottom of the screen regardless of depth sprite.y = camera.y + canvas.height * 0.5 / sprite.depth} Your render() function no longer needs to call the .translate() method, it just needs to call drawImage for each sprite var screen = getScreenCoordinates(sprite);drawingSurface.drawImage( sprite.image, sprite.sourceX, sprite.sourceY, sprite.width, sprite.height, screen.x, screen.y, sprite.width, sprite.height);
  21. Ingolme

    JQuery

    You can put content from a file into an element using jQuery's load() method.
  22. A while loop constantly keeps running the same code over as fast as it can. By the time a second has passed you'll have a million timers going on which will run the same function one second after they were created. You're also trying to declare a function inside a loop, meaning it's redeclaring the function millions of times a second. It's a bad idea to pass a string to setTimeout() or setInterval(). You should pass a function reference instead, like this: setTimeout(change, hold); The document.elementName method to refer to elements is not standard. The name attribute is not allowed on any element except <input>, <select> and <textarea>. Make sure you validate your code at http://validator.w3.org/ To access an element use the ID attribute and getElementById(); <img id="rollover" src="image_n_308x70.jpg" alt="Image" width="308" height="70">var image = document.getElementById("rollover"); Here's the solution to your problem: // Creating an array the modern way// No need for new Image(), just remember the image namevar rollover = [ "image_n_308x70.jpg", "image_d_308x70.jpg"];// Global variablesvar number = 0;var hold = 5000;// Set the timer, calling the function by referencesetTimeout(change, hold);// The functionfunction change() { // Access the element by its ID // Make sure the image has an id attribute document.getElementById("rollover").src = rollover[number]; // Get next number and time interval if(number == 0) { number = 1; hold = 1000; } else { number = 0; hold = 5000; } // This function calls itself so that it will repeat setTimeout(change, hold);}
  23. Javascript has its own internal Number type which is 32-bit float. Numbers can be treated as integer but I'm not sure if it actually casts to an integer type internally or it's just operating with whole numbers. It sounds like BCO16 is just a hexadecimal number. You can use the .toString() method on a Javascript number to represent in a different format. However, it's a string, a series of characters, and needs to be cast to a number again if you want to operate with it. // Represent num as a hexadecimal number (base 16)var num = 520;var result = num.toString(16);
  24. If you're testing on your local filesystem, the xmlhttp.status is always 0, never 200, because there's no server. Also make sure that the file "ajax_info.txt" exists.
×
×
  • Create New...