Trigger Mouse Events With Shapes Drawn In An HTML5 Canvas?
Jul 17, 2010
Is it possible to trigger mouse events with shapes drawn in an HTML5 canvas? I want to create a page with drawn elements that you can mouseover and pop up a dialogue box. I also want the shapes to react with some type of feedback. I'm hoping I can do this with javascript instead of Flash but haven't found a way to do it that's simple enough to make it worth it.
I am trying to create an Asteroids type game using JavaScript along with html5's canvas element for drawing. I have searched around and have looked at examples but I can't figure out what is wrong with my rendering that I do in the game loop that is run every frame. The problem appears to be only that the canvas is not cleared at the beginning of each frame but I feel there might be something wrong also. The code used and shown below only works in Firefox but not Google Chrome or Safari.
I want to save my canvas-content to a single image-file. There are an approach using todataurl(), which works fine. But not if i draw an image-file (e.g. car.jpg or house.png) to the canvas additionally. It does not return the whole image? Here I have my simple example-code:
I'm trying to figure out how to add images to a canvas element. I found a good site, but for some reason my images turn out bigger than expected.
Here's what I use (It's from different functions in different places, but essentially that is the relevant code). Assume there is a gameObject which has all the functions that I use. I tried replacing the functions with constant values but that made no difference:
PHP Code:
Somehow the image shows up much bigger than 69 pixels width and height. When I make the canvas smaller the image scales down with the canvas. So when I make the canvas twice as small, the image becomes twice as small as well. Seems like it is not using pixels as units.
Picture: Doing in html5 canvas, so JavaScript (was not sure where to post, but here I go...). Above is a link to picture that I need to do. It is clock-like. I will have to draw a circle, and two lines, from centre to according points on circle. That is not a problem, the thing I can not do is to fill upper and lower parts of circle that those two lines divide, so upper part of a circle should be e.g. red, and lower blue. (Plus, it would have to bi gradient, to look more appealing).
I am trying to get a function to draw 5 randomly sized and colored rectangles nested within each other. Meaning each rectangle should not go outside the boundaries of the rectangle it is in. The color thing I've got down in a randomColor() function. It's the nesting rectangles inside rectangles that is confusing me (hense me being up for the past 4 hours trying to understand it) I started out with very simple code just making 5 rectangles of reducing sizes nested in each other, then added the Math.random to randomize all the sizes. Now I'm at this point and have lost my way. I added a bunch of comments in my code so maybe you'll understand what I'm trying to do.
Now this code works on ios safari 4.2 and later but i can't get it to work on ios safari 4.1. On 4.1 it displays the canvas but will not draw the image. The debug console shows no errors. Is there anyway to get it to work, or is 4.2 the cut off point for even the most basic canvas operations?
I made the following, but wanted the user action to update the audio player status without a page refresh. Currently, the code opens another page with just the player and plays the track picked. How could I make this so only the player src="" changes and nothing else.
I set them all to hide - and provide a link to (show) each of them I need to make it so that the {click} of a link shows the corresponding paragraph AND hides the other paragraphs.
I have a set of links which get assigned listeners by a 3rd party javascript. What I'd like to do is simulate a click of the first anchor (which is dynamically built with PHP), so the click events trigger.
I have successfully managed to get a pop up dic with a faded black background to trigger when a link is clicked but i really need to trigger the pop up if the users mouse is idle for 1 minute.
I found thisClick Herewhich looks like the timer idle script but i cannot figure out how to implement it with my script.
heres the .js file i have already
var $j = jQuery.noConflict(); $j(document).ready(function() { //When you click on a link with class of poplight and the href starts with a #$j('a.poplight[href^=#]').click(function() {
I would like to make the onMouseOver event for an IMG swap 2 images. I currently have a javascript function for this (I didnt write it) which just inputs which image you want to swap and what with. I want to swap 2 images and not just one.
There is the code for the IMG tag, now the part where it does the onMouseOver it changes out the image of my choice. It calls the MM_swapImage. I want to call that function twice with diffrent parameters. I tried adding another onMouseOver line after the first one, but didnt work. Is there a way to do this in HTML? Hope that made sense.
On mouse over i want the back ground to be bgcolor='#993333'
On mouse out i want the back ground to be bgcolor='#FFFFFF'
Also on mouse over i want to display information about the row content inside a div tag <div id="content"></div>. This information can be plain text or links. Information is already created.
How can i accomplish this? Can i accomplish background through css?
If a div is positioned block or relative, events fire over the entire area of the div. If the div is positioned absolute they don't--they only fire over the div's text or image child elements, if any. This isn't true in FF or Opera, nor was it true in IE 5. If there is any logic in this behavior.
I want to temporaraly disable events from my page. However, I cant seem to get it to work. It will show my disables message, but then it goes ahead and does the action I was trying to do (like clicking on a link).
Here is the code, any ideas? ----- function disableEvents() { document.onclick = showDisabledMessage; } function enableEvents() { document.onclick = null; } function showDisabledMessage() { alert("Please wait for the current action to complete."); return false; }
This below would be my ideal code.... if it worked.
<html><head><script>
function mouseDownClass(o){
this.o = o;
this.handleMouseUp = function() { alert(this);
} //treating this section as the constructor (which sets up the mouseup listener as the method of an instantiation, ideally) document.body.addEventListener("mouseup",this.handleMouseUp,false);
alert() is showing 'this' to as: [object HTMLBodyElement] whereas i'm looking for it to show [object Object], (On Firefox at least), referring to the object instantiated when the mouse goes down on the button. I'd appreciate anyone who can help me here?
where they enlarge a thumbnail on mouse over events? I have seen a lot out there, but all seem to want to replace the image with a new larger image of the same kind. What I would prefere for it to do is enlarge or zoom the thumbnail image, so that 2 images are not needed for every image.
I did find somthing which does exactly what I need, but the enlarged image keeps flashing on and off for some reason. This is the code
<script type='text/javascript'> function get(eid) { var d = document;
[Code].....
I would imagine it has somthing to do with the pop image function, but not to sure.
I'm trying to figure out a way to make only one element on a page receive key and mouse events. I have a grid in a <div>-container with "overflow:auto" which makes the grid scrollable. If course I can set event handlers to the "document" to catch key strokes and mouse clicks and execute navigation functions which make the grid scroll (e.g. pressing down arrow) etc. This of course effects the whole page and not just the div.
The problem is: as far as I know only window and form elements can receive events such as focus(), blur(), keypress() etc. and I have to make sure only this one element is affected.
Is there thus a way to make these events affect only the <div> container?
The best way to do this would be with an event listener as this would make development much easier.
I'm working on a sliding drawer script which uses Prototype/Scriptaculous.
The script is simple, when I move my mouse over a certain region, the drawer slides out - when my mouse leaves that drawer, it slides back in. For some reason the event seems to occur while my mouse is over. Code:
I have 2 divs, one on top of the other. The top div merely holds some overlay imagery ( such as a glare ). The lower div has a menu in it, and thus needs mouseovers, etc. However, the top div is preventing the lower div from getting mouseevents.
1. Is there any possibility to find out if mouseover, mouseout or any other mouse event is taking place for the given element right now? 2. Is there any possibility to find out for which element such event is taking place right now?
I want to adjust the layout of the default lazy susan animation for this plugin. There are 5 slides. How would I need to adjust the JavaScript so that there are always 2 slides on the left and two slides on the right of the main slide that happens to be in focus? The shapes plugin offers a figure 8 shape that does this, but the animation style is not what the client wants.
Here's the URL with the working code. I've adjusted line 88 in the JS file, and it sort of gets me there: Code: var period = jQuery.roundabout_toFloat(180.0/ref.children(options.childSelector).length) //this is the original line var period = jQuery.roundabout_toFloat(360.0/ref.children(options.childSelector).length);