How to Slide right to left JQuery HTML CSS - javascript

$(document).ready(function() {
$("#One").click(function() {
$("#Two").animate({
width: 'toggle'
}, -10);
});
});
<script src="jquery-3.2.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-
3.2.1.min.js"></script>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script src="http://jquery-
ui.googlecode.com/svn/tags/latest/ui/jquery.effects.core.js"></script>
<script src="http://jquery-
ui.googlecode.com/svn/tags/latest/ui/jquery.effects.slide.js">
</script>
<script>
</script>
<div id="One" style="width:50px;height:200px;background-
color:yellow;position:relative;top:300px;left:600px;">One</div>
<div id="Two" style="width:200px;height:200px;background-
color:black;position:relative;top:100px;left:400px;">Two</div>
Above is the code, my problem exactly is that I can't get it to slide normally. When I click on it it disappears then comes back on the second click. I just want it to slide normally.

Try adding this::
$(document).ready(function() {
$("#One").click(function() {
$("#Two").animate({
left: '400px'
});
});
});

Related

load another page when slide toggle

I want to click a button on my page then another div toggle on and load in that div another page, but it doesn't work.
HTML:
<html>
<head>
<script type="text/javascript" src="js/jquery-1.7.2.min_1.js"></script>
<script>
$(document).ready(function() {
$('#clickme').click(function() {
$('#me').animate({
height: 'toggle'
}, 1000
);
$("#me").load("page2.html")
});
});
</script>
</head>
<body>
<div id="clickme" style="color: #FFFFFF;">
Click here
</div>
<div id="me" style="border:1px solid #000; width:900px; height:300px;">
</div>
</body>
</html>
I believe your function can be simplified to use the normal callback of toggle or slidetoggle
$(function() {
$('#clickme').on("click",function() {
$('#me').toggle(function() {
$(this).load("page2.html");
});
});
});
But you might want to load before toggling:
$(function() {
$('#clickme').on("click",function() {
$('#me').load("page2.html",function() {
$('#me').slideToggle();
});
});
});

jQuery UI Modal Popup Window on Button Click

I try to run some examples from Jquery site and some videos i' ve seen, but it seems like i can't execute them properly. Here's my code :
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function() {
$("#btnclick").click(function() {
$("#divpopup").dialog({
title: "blabla",
width: 430,
height: 200,
modal: true,
buttons: {
Close:
function() {
$(this).dialog('close');
}
}
});
});
})
</script>
</head>
<body>
<div id="divpopup" style="display:none">
blablablabla
</div>
<button type="button" id="btnclick">Click me</button>
</body>
</html>
I can't find what's wrong, the only thing it may be is that i haven't input an important library or something. Every one of my explorers shows me the button, but clicking it doesn't trigger the modal window. Any ideas?
Thank you
Jquery library references should be in below order.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

I have 9 small images that when clicked on, will fade in the bigger version of the image. Why wont work in Browser(FF))

<style type="text/javascript" src="jquery-1.11.0.min.js"></style>
<style type="text/javascript" src="myCode.js"></style>
</body> //jquery is within my site directory on my desktop
$(document).ready(function(){
//note:
$("#artShow,#changreImage,#clasziImage,#comicImage,#planetImage,#dragonImage,#wineImage,#underwaterImage,#catImage").mouseenter(function(){
$(this).animate({height:"125px",width:"136px"});
});
$("#artShow,#changreImage,#clasziImage,#comicImage,#planetImage,#dragonImage,#wineImage,#underwaterImage,#catImage").mouseleave(function(){
$(this).animate({height:"118px",width:"129px"});
});
//note:hover function
//When user clicks on a small image with the prior image hover function, bigger versions
on that image should fade in//
$("#big").hide();
$("#artShow").click(function(){
$("#big").fadeIn(2000);
$("#big").click(function(){
$("#big").fadeOut(2000);
});
});
$("#big2").hide();
$("#changreImage").click(function(){
$("#big2").fadeIn(2000);
$("#big2").click(function(){
$("#big2").fadeOut(2000);
});
});
$("#big3").hide();
$("#clasziImage").click(function(){
$("#big3").fadeIn(2000);
$("#big3").click(function(){
$("#big3").fadeOut(2000);
});
});
$("#big4").hide();
$("#comicImage").click(function(){
$("#big4").fadeIn(2000);
$("#big4").click(function(){
$("#big4").fadeOut(2000);
});
});
$("#big5").hide();
$("#planetImage").click(function(){
$("#big5").fadeIn(2000);
$("#big5").click(function(){
$("#big5").fadeOut(2000);
});
});
$("#big6").hide();
$("#dragonImage").click(function(){
$("#big6").fadeIn(2000);
$("#big6").click(function(){
$("#big6").fadeOut(2000);
});
});
$("#big7").hide();
$("#wineImage").click(function(){
$("#big7").fadeIn(2000);
$("#big7").click(function(){
$("#big7").fadeOut(2000);
});
});
$("#big8").hide();
$("#underwaterImage").click(function(){
$("#big8").fadeIn(2000);
$("#big8").click(function(){
$("#big8").fadeOut(2000);
});
});
$("#big9").hide();
$("#catImage").click(function(){
$("#big9").fadeIn(2000);
$("#big9").click(function(){
$("#big9").fadeOut(2000);
});
});
});
<style type="text/javascript" src="jquery-1.11.0.min.js"></style>
<style type="text/javascript" src="myCode.js"></style>
Shouldn't it be:
<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="myCode.js"></script>
?
tag should be script.
<script type="text/javascript" src="jquery-1.11.0.min.js"></script >
<script type="text/javascript" src="myCode.js"></script>
</body> //jquery is within my site directory on my desktop
$(document).ready(function(){
//note:
$(".img")
.mouseenter(function(){
$(this).animate({height:"125px",width:"136px"});
})
.mouseleave(function(){
$(this).animate({height:"118px",width:"129px"});
});
});
myCode.js
$(document).ready(function(){
$(".big-img").hide();
$(".img").click(function(){
var id = $(this).data(id);
$("#"+id)
.fadeIn(2000)
.click(function(){
$(this).fadeOut(2000);
});
});
});
HTML image
<img class="img" src="" data-id="artShow">
<img class="big-img" src="" id="artShow" >

Having trouble getting jqueryrotate to work

I am not having any luck getting jqueryrotate example #2 on this page to work on a simple html page. What am I doing wrong? Thanks for the help.
Here is my code -
<!DOCTYPE html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="http://jqueryrotate.googlecode.com/svn/trunk/jQueryRotate.js"></script>
<STYLE type="text/css">
#img { margin:100px 100px;}
</STYLE>
</head>
<body>
<script type="text/javascript">
$("#img").rotate({
bind:
{
mouseover : function() {
$(this).rotate({animateTo:180})
},
mouseout : function() {
$(this).rotate({animateTo:0})
}
}
});
</script>
<img id="img" src="https://www.google.com/images/srpr/logo3w.png">
</body>
</html>
you code works just fine, see here.
You should probably use ready.
$(document).ready(function() {
$("#img").rotate({
bind: {
mouseover: function() {
$(this).rotate({
animateTo: 180
})
},
mouseout: function() {
$(this).rotate({
animateTo: 0
})
}
}
});
});​
Also, I would not recommend using the id #img it's not that it's wrong, it's just sort of ugly IMO.

jQuery to animate image from left to right?

I have a Bee image and I want to animate it using jQuery.
The idea is to move the image from left (outside of screen) to right (outside of screen) to create an effect like it's flying.
Your bee needs to be absolutely positioned, something like this:
<div id="b" style="position:absolute; top:50px">B</div>
I've used a div here, but it could just as well be an <img> tag. As meo pointed out, don't forget the top attribute, because some browsers don't work without it. Then you can animate it:
$(document).ready(function() {
$("#b").animate({left: "+=500"}, 2000);
$("#b").animate({left: "-=300"}, 1000);
});
Here is a jsfiddle demo.
If you want to have a continuous animation as Hira pointed out, put the animation code in functions, make sure the left and right movement is the same, and use the onComplete option of animate() to call the next animation:
function beeLeft() {
$("#b").animate({left: "-=500"}, 2000, "swing", beeRight);
}
function beeRight() {
$("#b").animate({left: "+=500"}, 2000, "swing", beeLeft);
}
beeRight();
And the fiddle for that.
Try spritely: http://spritely.net/
i would do something like this:
http://jsfiddle.net/Uwuwj/2/
var b = function($b,speed){
var beeWidth = $b.width();
$b.animate({ //animates the bee to the right side of the screen
"left": "100%"
}, speed, function(){ //when finished it goes back to the left side
$b.animate({
"left": 0 - beeWidth + "px"
}, speed, function(){
b($b, speed) //finally it recalls the same function and everything starts again
});
});
};
$(function(){ //document ready
b($("#b"), 5000); //calls the function
});
bee careful, this code only works with bee's :P
In case you want the bee to keep flying across the screen, try this :-)
<html>
<head>
<script type="text/javascript" src="jquery/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
function animateImage() {
console.log("Called");
$('#bee').css({right:'10%'});
$('#bee').animate({right: '-100%'}, 5000, 'linear', function(){animateImage();});
}
$(document).ready(function() {
animateImage();
});
</script>
</head>
<body>
<div style="width: 100%;"><img src="bee.jpg" id="bee" style="position:relative;"/></div>
</body>
<script type="text/javascript" src="jquery/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
function rgt() {
$('#sldr').animate({ left: "500" }, 10000, hider);
}
rgt();
function hider() {
$('#sldr').css('left', '0px');
rgt();
}
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<img id="sldr" src="../Images/animated%20images/birds/rightfuglan.gif" style="position:absolute" />
</div>
</form>
</body
>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="../Scripts/jquery-1.10.2.js" type="text/javascript"></script>
<title></title>
<script type="text/javascript">
$(document).ready(function () {
var k = $(window).width();
function rgt() {
$('#sldl').hide(1);
$('#sldr').animate({ left: "1000" }, 10000, hider);
}
rgt();
function hider() {
$('#sldr').css('left', '0px');
$('#sldr').hide(1);
$('#sldl').show();
lft();
}
function lft() {
$('#sldl').animate({ left: "0" }, 10000, hidel);
}
function hidel() {
$('#sldl').css('left', '1000px');
$('#sldr').show();
rgt();
}
});
</script>
<style type="text/css">
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<img id="sldl" src="../Images/animated%20images/birds/fuglan.gif" style="position:absolute; right:0px" />
<img id="sldr" src="../Images/animated%20images/birds/rightfuglan.gif" style="position:absolute" />
</div>
</form>
</body>`enter code here`

Categories