I am trying to move around the image all over the screen but it only move from top to bottom and left to right and then it stops.
here is my javascript Code.
$(function(){
$("#btn1").click(function(){
$("#p2").animate({width:300 })
$("#p2").animate({left:'600px'})
$("#p2").animate({top:'400px'})
$("#p2").animate({right:'100px'})
$("#p2").animate({bottom:'400px'})
});
});
here is my html
<img src="myimage.png" id="p2" />
<button id="btn1">click</button>
<style>
#p2{
position:absolute;
}
</style>
if anyone have idea that how i can animate a image all around the screen then please help me out to solve my assign .thanks for your time .
<script>
$(document).ready(function(){
$("#b").animate({left: "+=500"}, 2000);
$("#b").animate({top: "+=300"}, 1000);
$("#b").animate({left: "-=500"}, 1000);
$("#b").animate({top: "-=300"}, 1000);
});
</script>
<div id="b" style="position:absolute; top:50px">
<img src="img/codelab-1.jpg" width="200px"/></div>
Related
I want to make a couple things happen here:
Start button starts the animation and then turns into Stop button.
Stop button then stops animation where it is and turns back into Start button and enables me to resume from where it stopped.
Instead the animation just disappears once i press start or stop again.
I am a newbie when it comes to this kind of stuff, if I am not clear in my intent please tell me so, and I will try to clear it up as best as I can.
<html>
<head>
<meta charset="UTF-8">
<style>
div {left: 0px;
bottom: 100px;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
move();
Stop();
});
function move(){
$("input").click(function(){
$(this).val('Stop');
$("div").css({left:'0%'}).animate({left:'100%'},1000, Stop);
Stop();
});
}
function Stop(){
$("input[value='Stop']").click(function(){
$( ":animated" ).stop(true, true, false);
$(this).val('Start');
move();
});
}
</script>
</head>
<body>
<h1 style="text-align:center"> Welcome to the test</h1>
<input type='button' value='Start' id='oneButton'>
<div style="height:100px;width:100px;position:absolute;">
<img id='myRobot' src='myRobot.jpg' width="250px" height="200px"/>
</div>
</body>
</html>
Your JavaScript code is a little bit messy. First of all your move function:
function move(){
$("input").click(function(){
$(this).val('Stop');
$("div").css({left:'0%'}).animate({left:'100%'},1000, Stop);
Stop();
});
}
Your Stop function (not the one set as callback function of the animate function) will be called while the div is animated. You don't want this.
What you might wants is essentially three different functions:
move
pause
reset
Your move function will essentially start to move your object, the pause will obviously pause it, while the reset will put your object in the initial position, if you wanto so.
Let say your HTML file is structured like this:
<h1 style="text-align:center"> Welcome to the test</h1>
<input type='button' value='Start' id='oneButton' />
<div id="object">
<img id='myRobot' alt='test' src='http://www.clker.com/cliparts/7/b/d/b/1237099752389782475nicubunu_Soccer_ball.svg.thumb.png'/>
</div>
Your CSS:
#object {
position: absolute;
left: 0px;
bottom: 100px;
width: 100px;
height: 100px;
}
And finally the JS:
var animating = false;
$("#oneButton").on("click", function() {
if (!animating) {
$(this).val("pause");
move();
} else {
$(this).val("start");
pause();
}
});
function move() {
animating = true;
$("#object").animate({left:'100%'},1000, reset);
}
function pause() {
$("#object").stop();
animating = false;
}
function reset() {
animating = false;
$("#object").css({left: '0%'});
}
Here is a FIDDLE where you can seet in "action".
I have a div where certain controls which are added dynamically after getting data from database.
Its kinda news details that are going to get added. I just wanted that news to scroll automatically which I have achieved through javascript.
Now if I want to stop the animation on mouseover and continue on mouseout how can I modify the javascipt.
This is my html page:
<section id="secbody" runat="server" style="position:absolute; background-color:dimgray; max-height:183px; min-height:183%;margin-top:14px;margin-left:545px;width:535px;">
<div id="galheader" style="width:535px;" runat="server">
<label id="Label1" style="color:White; position:absolute; font-size:20px; left:20px; height: 26px; width: 100%;" runat="server"> Upcoming Programs</label>
</div>
<section id="secdetails" runat="server" style="font-family:'Palatino Linotype';color:white; min-width:500px;overflow-wrap:break-word;background-attachment:fixed;position:absolute;margin-top:25px;"></section>
</section>
and this is my javascript
<script type="text/javascript">
$(document).ready(function(){
function marqueePlay(){
$("#secdetails").animate(
{
top: $("#secbody").height() - $("#secdetails").height(),
opacity: 1
}, 4000, function(){
$("#secdetails").css("top", 1);
$("#secdetails").css("opacity", 1);
marqueePlay();
}
);
}
marqueePlay();
});
</script>
I know we need to use .stop functionality but do not know the proper way to use it.
You can use .hover() function to accomplish your task
Try,
$("#secdetails").hover(function(){
$(this).stop(); //Stop the animation when mouse in
},
function(){
marqueePlay(); //Start the animation when mouse out
});
How about this?
function stopAnimation(){
$("#secdetails").stop();
}
<div id="secdetails" onmouseout="marqueePlay()" onmouseover="stopAnimation()"></div>
I've been looking around and I think I'm fairly close to getting this but when I move my slider to alter the speed of the animation, nothing seems to happen. I'm assuming this has something to do with the animation already in progress? Here's the code I have thus far:
<html>
<head>
<script src="jquery-1.10.1.js" type="text/javascript"></script>
<script type="text/javascript">
function pageScroll(speed)
{
$("html, body").animate({ scrollTop: $(document).height() }, speed);
}
</script>
</head>
<body>
<body onLoad="pageScroll(100000);">
<input onChange="pageScroll(this.value);" type="range" value="100000" name="slider" min="0" max="200000" style="position:fixed; left:0;top:0">
<center><img src="page-0.jpg" width="800">
<img src="page-1.jpg" width="800">
<img src="page-2.jpg" width="800">
<img src="page-3.jpg" width="800"></center>
</body>
</html>
Please delete these Part of your code <body onLoad="pageScroll(100000);">
And you have 2 body tags in your code... It's not good...
If you want to do something, when your page is loaded, then do it in JS with helps of jQuery ->
$(function() {
/* things to do, after the page is loaded */
pageScroll(100000);
});
To change the animation, use .stop(). It breaks all animations in queues. For more information, read API docs
function pageScroll(speed) {
$("html,body").stop().animate({ scrollTop: 119}, 500 );
}
And i'm not sure, but i think i had some Problem with this selector... if it doesn't work, try this selector:
$("html:not(:animated),body:not(:animated)")
You could do something like this:
http://jsfiddle.net/ASMITH/AECva/
<input id="slider" type="range" value="10000" name="slider" min="100" max="20000" style="position:fixed; left:0;top:0"></input>
$(document).ready(function () {
var vHeight = $('body').height();
$('#slider').change(function () {
var speed = $('#slider').val();
$('body').stop().animate({
scrollTop: vHeight
}, +speed);
});
});
Below is my original question and code but per CoreyRS's comment let me add some detail. I want to create a div that falls own the page and disappears like a rock falling through the air. The catch is it must work in IE 9 and 8. I have found some CSS3 animations that work great in all but IE. Any help is appreciated. Please provide code examples.
Original Question and Code
I am attempting to use the slideDown animation in jQuery to animate a div. The idea is a div will show then slide down the page and then fade out. Preferably it would fade out while falling but I cannot even get the div to fall. Here is my code:
JS:
var $j = jQuery.noConflict();
$j(window).load(function() {
$j('#loading').fadeOut('slow', function() { //fade out loading div
$j("#content-wrap").fadeIn("slow", function() { // show content div
setTimeout( function() { // delay slideDown effect
$j('#animate').slideDown('slow', function() {
// script to fade out or hide animate div
}, 2000 );
});
});
});
});
HTML:
<div id="loading">
<h2 class="textcenter">Loading...</h2>
<img id="loading-image" class="center" src="/images/ajax-loader.gif" />
</div>
<div id="content-wrap" class="hide">
<div id="animate">
<img class="fear" src="/sign.png" />
</div>
<div class="img-center">
<img class="feature-image" src="/Prairie-Grass.jpg" />
</div>
</div>
What am I doing wrong and I will take any advice that will create a falling div on the screen that fades out that will work in IE 9 and 8.
Haven't tested but give this a go. You'll need to edit the width/height properties etc to your needs, and obviously don't use inline styling if you have a css stylesheet.
<style>
#animate {
width:100px;
height:100px;
position:fixed;
top:-100px;
left:50%;
margin-left:50px;
z-index:1;
}
</style>
<script>
var $j = jQuery.noConflict();
$j(window).load(function() {
$j('#loading').fadeOut('slow', function() {
$j("#content-wrap").fadeIn("slow", function() {
$j('#animate').delay(2000).animate({'top':'50%'}, 500);
$j('#animate').delay(2000).fadeOut(500);
});
});
});
</script>
Here is this simple slideshow I'm using:
function slideShow(){
var current = $('#animation .show');
var next = current.next().length ? current.next() : current.parent().children(':first');
current.removeClass('show');
next.addClass('show');
setTimeout(slideShow, 500);
}
$(document).ready(function() {
slideShow();
});
It works but it creates long pauses between images...Is there a way to fix this?
Thanks in advance!
EDIT
this is the HTML code,I guess pauses was the wrong word, what I want to achieve is every image is displayed immediately after the other, right now I have a small gap that nothing is displayed.
<div id="animation">
<img alt="graphic" class="show" src="files/animation_img/GRAPHIC.jpg" />
<img alt="design" src="files/animation_img/DESIGN.jpg" />
<img alt="etc" src="files/animation_img/ETC.jpg" />
</div>
and the CSS:
#animation img
{
position:fixed;
top:400px;
left:700px;
display:none;
visibility:hidden;
width:200px;
height:100px;
}
Try this
function slideShow(){
var current = $('#animation .show');
var next = current.next().length ? current.next() : current.parent().children(':first');
current.removeClass('show');
next.addClass('show');
}
$(document).ready(function() {
setInterval(slideShow, 500)
});