I have a simple animation made in Flash which is colour changing wheel wheel, and GIF ready too. When somebody goes to my site, the wheel keeps animating.
But what I need is that when someone presses the "Stop Animation" button near the animation, a message to be displayed on the screen. It would be better if it can be popped out and can be sent to the user's email id he inputs.
A great thanks from my side to someone who can help me.
Here is the HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CreateJS export from Anime</title>
<script src="http://code.createjs.com/easeljs-0.6.0.min.js"></script>
<script src="http://code.createjs.com/tweenjs-0.4.0.min.js"></script>
<script src="http://code.createjs.com/movieclip-0.6.0.min.js"></script>
<script src="Untitled-1.js"></script>
<script>
var canvas, stage, exportRoot;
function init() {
canvas = document.getElementById("canvas");
exportRoot = new lib.Untitled1();
stage = new createjs.Stage(canvas);
stage.addChild(exportRoot);
stage.update();
createjs.Ticker.setFPS(2);
createjs.Ticker.addEventListener("tick", stage);
}
</script>
</head>
<body onload="init();" style="background-color:#D4D4D4">
<canvas id="canvas" width="550" height="400" style="background-color:#ffffff"> </canvas>
Related
<!DOCTYPE html>
<html>
<head>
<title>Snake!!</title>
<link rel="stylesheet" href ="snake.css">
</head>
<body scroll="no" style="overflow: hidden">
<div class="canvas-container">
<img src="Apple.png" width="0" height="0" id="Apple"><!--Image-->
<canvas id="myCanvas"></canvas> <!-- canvas for the game-->
<button type="button" onclick="restartGame()"class="Restartbutton" id="myButton">Restart</button>
<textarea class="score"id="score" ></textarea>
<script src="snake.js"></script>
</div>
</body>
</html>
const Canvas = document.getElementById("myCanvas");<!-- start of JS-->
const ctx = Canvas.getContext("2d");
const imgApple = document.getElementById("Apple");
function draw(){
ctx.drawImage(imgApple,200,200,50,50);<!-- just random numbers to place the Apple at-->
ctx.fill();
requestAnimationFrame(draw);
}
requestAnimationFrame(draw);
I wanted to make an Snake game. I drew all the canvas and buttons for the game and now I just want to have a player or an Apple in the game as Images. I need help.
Thx already!
The problem is that you didn't specify initial dimensions for your canvas - thus it's using the defaults of width=300 and height=150. Of course this wouldn't be much of a problem if there wouldn't be this line:
ctx.drawImage(imgApple,200,200,50,50);
This means it tries to draw the apple at screen position x=200 and y=200 - outside of the visible area of the canvas.
Try it with
ctx.drawImage(imgApple,200,100,50,50);
I am doing this small project - my cursor moves in a left rectangle and it should appear in the second one. I have made an image of cursor and I am trying to move it according to my cursor, but nothing happens. Could you help me to find the mistake? I would be very grateful!
Here is the code snippet:
<html>
<head>
<title>Laboratory work 1_4</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
#imgc{
position: absolute;
}
</style>
</head>
<body>
<img src="arrow.png" id="imgc" width="20" height="20">
<canvas id="canvas" width="800" height="600" ></canvas>
<script type="text/javascript">
var c = document.getElementById("canvas");
var ctx = c.getContext("2d");
ctx.rect(20, 20, 300, 200);
ctx.stroke();
ctx.rect(350, 20, 300, 200);
ctx.stroke();
</script>
<script type="text/javascript" src="js/libs/jquery/jquery.js">
$("#canvas").mousemove(function(e){
$("#imgc").stop().animate({left:e.pageX, top:e.pageY});
});
</script>
</body>
P.S. I added jquery library in a JavaScript libraries wizard in Netbeans. So the structure of my project looks like this:
I have created an HTML5 canvas game which involves dragging and selecting objects(words) from two canvases. The screen also has two buttons. But unfortunately my program is hard coded in terms of selecting words as I have entered the co-ordinates where the words are drawn on canvas. My screen resolution is 1366 x768. Now whenever the resolution is changed, the buttons move somewhere else and the mouse never selects the dragged words rather some words else above it. I am in a big trouble now, please help !!
<html>
<head>
<title>Word Search</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type = text/css href="style.css">
<script type="text/javascript" src="keywords.js"></script>
<script type="text/javascript" src="game.js"></script>
<script type="text/javascript" src="highlight.js"></script>
<script type="text/javascript" src="grid.js"></script>
<script src="http://code.createjs.com/easeljs-0.7.0.min.js"></script>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<h1 id="heading">Find Keywords</h1>
<h3 id="results">Drag through the lettered Squares..!</h3>
<canvas id ='canvas1' height = 450 width="450" style= "border :1px solid black"> </canvas>
<canvas id ='canvas2' height = 450 width="250" style= "border :1px solid black"></canvas>
<input type='button' value="HIGHLIGHT ALL" id="button1" onclick="highlight();" />
<input type='button' value="NEXT" id="button2" onclick="next();"/>
<script>
var words =[];
window.onload = function(){
begin();
};
function begin()
{
wordSearchPuzzle();
}
function wordSearchPuzzle()
{
words.length=0;
words = getwords(8);
var puz =wordfind(words);
game(words,puz);
}
function next()
{
var canvas = document.getElementById("canvas1");
var ctx1 = canvas.getContext("2d");
var canvas2 = document.getElementById("canvas2");
var ctx2 = canvas2.getContext("2d");
ctx1.clearRect(0, 0, canvas.width, canvas.height);
ctx2.clearRect(0, 0, canvas2.width, canvas2.height);
wordSearchPuzzle();
}
</script>
</body>
</html>
This is possible, I have done it int he past with a canvas that would be dynamically sized based on the screen size.
If I remember correctly i did something like this.
I placed the canvas in a div, and gave the div a dynamic width, something like style="width: 30%"
I placed the canvas inside this div and tied css to give the canvas a style="width: 100%"
<div style="width:30%">
<canvas id="can" style="width:100%"></canvas>
</div>
I tied into the window resized event and read the client size to determine the element width and height to change the canvas
window.resize = function(){
var canvas = document.getElementById("can");
canvas.width = canvas.clientWidth;
canvas.height = //some value based on width
}
You then need to redraw your canvas as resizing will clear the canvas of all content
I've just started to learn easeljs. I have tried to create a rectangle which will follow the mouse coordinates, but it is not working. What's wrong here and how it can be fixed?
fiddle
<html>
<head>
<style>
*{margin:0px;padding:0px;}
</style>
<script src="easeljs.js"></script>
</head>
<body>
<canvas id="mycanvas" width="500" height="500" style="border:1px solid black;"></canvas>
<script>
function init(){
var canvas=document.getElementById('mycanvas');
var ctx=canvas.getContext('2d');
var stage=new createjs.Stage(canvas);
var shape=new createjs.Shape();
shape.graphics.beginFill('red').drawRect(300,200,40,40);
stage.addChild(shape);
createjs.Ticker.addEventListener("tick",tick);
function tick(event){
shape.x=stage.mouseX;
shape.y=stage.mouseY;
stage.update(event);
}
}
window.onload=init;
</script>
</body>
</html>
You have set the x and y of your rectangle to be 300 and 200 respectively, so if you set those to 0, then the rectangle will start in the right place and follow the mouse as expected.
shape.graphics.beginFill('red').drawRect(0,0,40,40);
I'm creating a website at present.
There many sites/sources I have and could go to for doing what I want. But their ways/steps aren't working for me.
I have the following situation:
I have 2 cols in Dreamweaver.
1 for images and the right col for text.
I want the user to click on the image and hear the audio of the person in the picture.
No players or other pages opening. Click image and hear audio that's it.
Can this be done. As the current and only example seems to leave me uncertain:
http://www.it-student.org.uk/playsound/playsounds.php
I set it up as it asks nothing happens no sound.
<title>Untitled Document</title>
<script>
function EvalSound(soundobj) {
var thissound= eval("document."+soundobj);
thissound.Play();
}
</script>
</head>
<body>
<embed src="hannbil smith.mp3" autostart=false width=0 height=0 name="sound1" enablejavascript="true">
<img src="han cast.jpg"">
</body>
</html>
This can be done easily using jQuery
DEMO jsFiddle
var manifest = [
{id:"waiting", src:"http://stardotserver.co.uk/waiting2.ogg"}
]
var preload = new createjs.LoadQueue()
preload.installPlugin(createjs.Sound)
preload.loadManifest(manifest)
$('img').on('click',function() {
createjs.Sound.play("waiting", createjs.Sound.INTERRUPT_NONE, 0, 0, -1, .5)
});
You AT LEAST need to close the embed tag and remove spaces from the URL.
Also EVAL is EVIL. Lastly return false from the onclick
I gave it an ID and use getElementById
<!DOCTYPE html>
<html>
<head>
<title>Untitled Document</title>
<script>
function evalSound(soundobj) {
var thissound=document.getElementById(soundobj);
thissound.Play();
return false;
}
</script>
</head>
<body>
<embed src="hannbil%20smith.mp3" autostart=false width=0 height=0 name="sound1" id="sound1" enablejavascript="true" />
<img src="han%20cast.jpg"">
</body>
</html>