how to change image when ball put into box? - javascript

I am trying to do some animation using css or jquery .my ball is put into box when I run my project .I want to change the image if ball is successfully insterted in box.
here is my code
https://jsbin.com/coyarezeto/1/edit?html,css,output
.container {
margin: 10px;
}
.circle0 {
border-radius: 50%;
height: 30px;
width: 30px;
margin: 10px;
background: PaleTurquoise;
position :relative;
-webkit-animation: mymove 5s; /* Safari 4.0 - 8.0 */
animation: mymove 5s;
animation-timing-function: ease-in-out; /* or: ease, ease-in, ease-in-out, linear, cubic-bezier(x1, y1, x2, y2) */
}
.newImage{
display:none;
position :absolute;
top:250px
}
#-webkit-keyframes mymove {
from {top: 0px;}
to {top: 200px; opacity: 0}
}
/* Standard syntax */
#keyframes mymove {
/* from {top: 0px;}
to {top: 250px;opacity: 0.2} */
0% {
top: 0px;
}
50% {
top: 100px;
}
100% {
top: 250px;
opacity: .3;
display:none
}
}
.img{
position :absolute;
top:250px
}
I want to change image when ball inserted into box after 5sec
<img class="newImage" width="100" src="https://previews.123rf.com/images/boygointer/boygointer1511/boygointer151100234/49187556-open-gift-box-over-white-background-3d-illustration.jpg"

I don't think this is something CSS can do, but it is something jquery can do witht he following code :
function imgChange(){
setTimeout(function(){ $('.img').attr({'src' : 'insertnewimg'}); }, 5000);
}
function ballTouch(){
//yadda yadda code that makes the ball move and detects when its ina box
if(ballIsInTheBox == true)
imgChange();
}
ballTouch();
setTimeout makes the program wait x, in this case 5000, miliseconds (1000 miliseconds = 1 second) before executing the code inside of it, which changes the image src in jQuery. Good luck, let me know if I screwed anything up. Note : Keep in mind setTimeout doesnt stop the whole program, just delays the function inside of it.

You can use setTimeout and display image after 5 secs. i.e :
//display image after 5 seconds
setTimeout(function() {
document.getElementById('myimage').style.display = 'block';
}, 5000);
.container {
margin: 10px;
}
.circle0 {
border-radius: 50%;
height: 30px;
width: 30px;
margin: 10px;
background: PaleTurquoise;
position: relative;
-webkit-animation: mymove 5s;
/* Safari 4.0 - 8.0 */
animation: mymove 5s;
animation-timing-function: ease-in-out;
/* or: ease, ease-in, ease-in-out, linear, cubic-bezier(x1, y1, x2, y2) */
}
.newImage {
display: none;
position: absolute;
top: 250px
}
#-webkit-keyframes mymove {
from {
top: 0px;
}
to {
top: 200px;
opacity: 0
}
}
/* Standard syntax */
#keyframes mymove {
/* from {top: 0px;}
to {top: 250px;opacity: 0.2} */
0% {
top: 0px;
}
50% {
top: 100px;
}
100% {
top: 250px;
opacity: .3;
display: none
}
}
.img {
position: absolute;
top: 250px
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<!-- <div class="container">
-->
<div class="circle0"></div>
<!-- </div>
-->
<img class="img" width="100" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxATDxUSEBAWFhUVFhcVFRIXEBcQEhcVFhEXFxUSFxUYHyggGBolGxMVITEhJSktLi4uFx8zODMtNygtLisBCgoKDg0OGhAQGy4mHR0tLi0tKy0tLystLS0tKy4rLTAtLTAtLS8rLS0tKy0tLS0tLy0tLS0tLS0rLS0rLS0rLf/AABEIAOMA3gMBEQACEQEDEQH/xAAcAAEAAgMBAQEAAAAAAAAAAAAABgcDBAUCAQj/xABIEAABAwECCgYGBwYFBQEAAAABAAIDEQQFBhIhMUFRYXGRsQcTMoGhwSIjQnKy0RQkM1Jic5IlgqKjwvBDRGOz4TRTg4TxCP/EABoBAQACAwEAAAAAAAAAAAAAAAABBAIDBQb/xAA2EQEAAgECAwUGBAYCAwAAAAAAAQIDBBEFEjEhMkFRcRMiYYGRsSPB0fAUMzRCoeEk8VKSsv/aAAwDAQACEQMRAD8AvFAQEBAQEBAQEBB8qgqPpffNNao4mEhkLcbIaVe/Oe5obxKpanebbeT03BopjxTeetp/xH+0GY+3s7Fomb7sz28itHvx4uttp7dax9IbLMJb2Zmtc368bmp9pkjxYTpNJbrSPozsw/vhv+ad3xRO5sKn22SPFhPDNHb+yPrP6tyDpVvRvadE73oQPhIUxqbw1W4LpbdImPn+u6zujXCmS8L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QTeJtGgagB4KWL2gICAgIID0r4EC3QdfA36zEPRpkMrM5jOsjKW7ajStd679sLmk1Hs7cs9JQy4DWyQ/ltHe30SPBTXpDVn/mW9W+smoQSC7z6pm7zKDYQEBAQEBB9BQfn9ct7wQEE/6KG/9Sfyhx6z5K1pvFweNz/L+f5LAVpwRAQZYbM93ZYTuGRB0ILikPaIb4lEbujBccQ7VXbzQcApN3URAgICAgICCEYYXCGevhbRpJ6xoFACTXHAGsk12naoTvv1RREiDv3YfUt7/iKDZQEBAQEBB5mNGuOpp5FJTXrCgly3uxAQWN0UxertDtb4x+lsh/qVvTdJee43b36R8J/L9FiwXZM7MwgazkCsuG6MGD/339zfmVJu6EF1wtzMB2n0kRu3ANSD6gICAgICAgICDy9gIIIqDkIOYjUgrbCO5zZ5cn2bsrDzadoUJchEu7dX2Ld7viKDbQEBAQEBBhthpE8/gf8AAVE9GWPvR6x91GWSxyyuxYo3vd91jC88AFzYiZ6PcWvWkb2nZLrp6L7zmoXRthB0yuxTT3WgniFtrgvKhl4rp8fZE7+ibXT0N2ZtDabQ+Q6WsAiZuJNT4hbq6aPGXNy8ayT3KxHr2p5clwWWyMxLNC1gJqc5JNKVLjlK31rFY2hys2fJmtzXneXTWTSICAgICAgICAgICAgINS87AyeIxvzHMdIOghBWFvsb4ZHRvGVvAjQRsUMnUug+qG880G4gICAg2oLvlf2WHecg4lEOhBg+723gbBlUm7oR3NAAQWY1QQcbLUEUI8U2ImYneGxYrDDE3FhiZG0eyxgYOACiIiOjK+S153tMzPxbClgICAgICAgICAgICAgICAgICDiYUXKJ48Zo9Yzs7RpafJBE7oBEZByEOOTuChk3443ONGtJ3CqDfguaZ2cBu8+QRDowXAwdtxOweiFJu6MFjjZ2WAbaVPFEM6AgICAgICAgICAgICAgICAgICAgICAg5bbviM7yWDLRx3kZTTuCDpRxtaKNAG4UQekBAQEBAQEBAQEBAQEBAQEBAQf/2Q=="
alt="">
<img class="newImage" id="myimage" width="100" src="https://cdn3.vectorstock.com/i/1000x1000/28/52/surprise-open-gift-box-vector-20692852.jpg" </body>

This is What I reached so far .. With help from Detect the End of CSS Animations and Transitions with JavaScript
You need to create animate class holds the animation
Add this class using javascript
Use a function to detect the end of css animation
Finally you can use .toggle() to toggle between images
$(document).ready(function(){
var animationEvent = whichAnimationEvent();
$(".circle0").addClass("animate");
$(".circle0").one(animationEvent,
function(event) {
$(".img , .newImage").toggle();
// Do something when the transition ends
});
});
function whichAnimationEvent(){
var t,
el = document.createElement("fakeelement");
var animations = {
"animation" : "animationend",
"OAnimation" : "oAnimationEnd",
"MozAnimation" : "animationend",
"WebkitAnimation": "webkitAnimationEnd"
}
for (t in animations){
if (el.style[t] !== undefined){
return animations[t];
}
}
}
.container {
margin: 10px;
}
.circle0 {
border-radius: 50%;
height: 30px;
width: 30px;
margin: 10px;
background: PaleTurquoise;
position :relative;
}
.circle0.animate{
-webkit-animation: mymove 5s; /* Safari 4.0 - 8.0 */
animation: mymove 5s;
animation-timing-function: ease-in-out; /* or: ease, ease-in, ease-in-out, linear, cubic-bezier(x1, y1, x2, y2) */
}
.newImage{
display:none;
position :absolute;
top:250px
}
#-webkit-keyframes mymove {
from {top: 0px;}
to {top: 200px; opacity: 0}
}
/* Standard syntax */
#keyframes mymove {
/* from {top: 0px;}
to {top: 250px;opacity: 0.2} */
0% {
top: 0px;
}
50% {
top: 100px;
}
100% {
top: 250px;
opacity: .3;
display:none
}
}
.img{
position :absolute;
top:250px
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<!-- <div class="container">
--> <div class="circle0"></div>
<!-- </div>
-->
<img class="img" width="100" src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxATDxUSEBAWFhUVFhcVFRIXEBcQEhcVFhEXFxUSFxUYHyggGBolGxMVITEhJSktLi4uFx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8AAVE9GWPvR6x91GWSxyyuxYo3vd91jC88AFzYiZ6PcWvWkb2nZLrp6L7zmoXRthB0yuxTT3WgniFtrgvKhl4rp8fZE7+ibXT0N2ZtDabQ+Q6WsAiZuJNT4hbq6aPGXNy8ayT3KxHr2p5clwWWyMxLNC1gJqc5JNKVLjlK31rFY2hys2fJmtzXneXTWTSICAgICAgICAgICAgINS87AyeIxvzHMdIOghBWFvsb4ZHRvGVvAjQRsUMnUug+qG880G4gICAg2oLvlf2WHecg4lEOhBg+723gbBlUm7oR3NAAQWY1QQcbLUEUI8U2ImYneGxYrDDE3FhiZG0eyxgYOACiIiOjK+S153tMzPxbClgICAgICAgICAgICAgICAgICDiYUXKJ48Zo9Yzs7RpafJBE7oBEZByEOOTuChk3443ONGtJ3CqDfguaZ2cBu8+QRDowXAwdtxOweiFJu6MFjjZ2WAbaVPFEM6AgICAgICAgICAgICAgICAgICAgICAg5bbviM7yWDLRx3kZTTuCDpRxtaKNAG4UQekBAQEBAQEBAQEBAQEBAQEBAQf/2Q==" alt="">
<img class="newImage" width="100" src="https://cdn3.vectorstock.com/i/1000x1000/28/52/surprise-open-gift-box-vector-20692852.jpg"
</body>
</html>
To be honest: simple way is to use setTimeout after 5 seconds .. If its not what you looking for then you can use my answer

Here is actual solution for your question :https://jsfiddle.net/t8re0vnk/1/
You can handle this by binding event to animation circle.
var element = document.getElementById("circle0");
element.addEventListener("animationend", function() {console.log('zxcxzc'); changeImg();}, false);
function changeImg(){
document.getElementById("img").src = 'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQqcPW3wEJ3qv3zjTkw5DQaDkgmCiTDclMKMVHp9RZ8VJpZkxal9g';
}
HTML:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<!-- <div class="container">
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
--> <div id="circle0" class="circle0"></div>
<!-- </div>
-->
<img class="img" width="100" id="img" src="https://mk0westpacklifeyuwd8.kinstacdn.com/wp-content/uploads/99508-gift-box-small-blue-34284-copy-1.jpg" alt="">
</body>
</html>

Related

animation like vertical scrolling div inside parallax

I am trying to do the animation, based on scroll, I already create float-animation in my keyframe. however it doesn't result to the same that I like. I wanted when scroll. then it will be like vertical carousel when scrolling. But the only difference I'm using keyframes and add that class whenever the scroll condition meet. I wanted when I scroll down then the .div1 will slide up and after the animation complete I wanted to show the .div2 .Then if the .div2 is current display when scroll up .div2 will animate slide down then when the animation done then .div1 will appear again just like in vertical carousel. Can someone help me. please
window.addEventListener("scroll", function() {
var elementTarget = document.getElementById("scrollTest");
let lastScrollTop = 0;
if (window.scrollY > elementTarget.offsetTop + 100) {
console.log("up 1");
$(".div2").show();
$(".div1").addClass("float-anim");
$(".div1").hide();
} else {
$(".div2").hide();
$(".div1").show();
}
});
body {
height: 200vh;
}
.div2 {
display: none;
}
.scrollTest {
position: fixed;
}
.float-anim {
position: relative;
-webkit-animation: floatBubble 9s;
animation: floatBubble 9s;
animation-fill-mode: forwards;
/*Safari and Chrome*/
-webkit-animation-fill-mode: forwards;
}
#-webkit-keyframes floatBubble {
100% {
top: -100rem;
}
0% {
top: 0px;
}
}
#keyframes floatBubble {
100% {
top: -100rem;
}
0% {
top: 0px;
}
}
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<div class="scrollTest" id="scrollTest">
<div class="div1">
<img src="https://i.pinimg.com/736x/f7/eb/d8/f7ebd86ff10d7d738d975f227a591600.jpg" width="50%" />
</div>
<div class="div2">
<img src="https://i.pinimg.com/736x/85/60/5a/85605a84fe1acc6e16ff5a84255b41ab.jpg" width="50%" />
</div>
</div>
</body>

Animating a diagonal line from corner to corner

I am trying to animate a diagonal line across the page from one corner to another. The line should be diagonal no matter the format of the screen. I figured (or so I think) that I have to use transform: rotate() in CSS. Using jquery or Javascript, I tried returning and calculating the degree at which the line has to rotate for the given screen format. That argument should be passed to rotate().
I've tried the following with jQuery and Javascript:
<script>
$('#move').css('transform', 'rotate(-' + Math.atan2($(window).width(), $(window).height()) + 'rad)').show();
</script>
or
<script>
document.querySelector('#move').style.transform = Math.atan2($(window).width(), $(window).height())+'rad';
</script>
And with CSS and HTML:
<style>
#move {
width: 0;
height: 4px;
background: red;
position: relative;
animation: mymove 3s;
animation-fill-mode: forwards;
transform-origin: top left;
}
#keyframes mymove {
from {top: 0; transform: rotate(0deg);}
to {width:100%; background-color: blue;}
}
</style>
<body>
<div id="move"></div>
</body>
The code draws a line across the screen, but it is not rotated.
How can that be fixed?
You have to put your <script> to the very bottom of <body>, so the code works after your DOM is loaded.
const move = document.querySelector('#move')
const angle = Math.atan2(document.documentElement.clientHeight, document.documentElement.clientWidth);
const width = document.documentElement.clientWidth / Math.cos(angle);
move.style.setProperty('--a', angle + 'rad');
move.style.setProperty('--w', width + 'px');
html, body, #move {margin:0; padding:0}
#move {
width: 0;
height: 4px;
background: red;
position: relative;
animation: mymove 3s;
animation-fill-mode: forwards;
transform: rotate(var(--a));
transform-origin: top left;
}
#keyframes mymove {
to {
width: var(--w);
background-color: blue;
}
}
<div id="move"></div>

How do i make the image appear at the same time as the next and to be on the rightt

The loading screen is loading to high up it needs to be under the menu section of the page to make it look more realistic, and how do I make the image appear at the same time as the text cause the image after the loading always comes up first
HTML
<!DOCTYPE HTML>
<HTML lang="en">
<head>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/CSS" href="dropdownmenu.css">
<link rel="stylesheet" type="text/CSS" href="rainbowheading.css">
<link rel="stylesheet" type="text/CSS" href="loadingcss.css">
<script src="loading.js"></script>
<title> North Macedonia </title>
<div class="container">
<h1 class="rainbow"> The pearl of the Balkans: Macedonia </h1>
<div class="navbar">
Home
Macedonian Dispora
Cities
<div class="dropdown">
<button class="dropbtn">History
<i class="fa fa-caret-down"></i>
</button>
<div class="dropdown-content">
Ancient History
Ottoman Period
Yugoslav Period
Modern History
</div>
</div>
</div>
</head>
<body onload="myFunction()" style="margin:0;">
<div id="loader"></div>
<div style="display:none;" id="myDiv" class="animate-bottom">
<h2>Welcome to my website about Macedonia</h2>
<p>x</p>
</div>
<div style="display:none;" id="MyDi" class="animate-bottom">
<img src="./images/ohridindex.jpg" class="center">
</body>
CSS (For loading) This is the main CSS document
/* Center the loader */
#loader {
position: absolute;
left: 50%;
top: 50%;
z-index: 1;
width: 150px;
height: 150px;
margin: -75px 0 0 -75px;
border: 16px solid #f3f3f3;
border-radius: 50%;
border-top: 16px solid #3498db;
width: 120px;
height: 120px;
-webkit-animation: spin 2s linear infinite;
animation: spin 2s linear infinite;
}
#-webkit-keyframes spin {
0% { -webkit-transform: rotate(0deg); }
100% { -webkit-transform: rotate(360deg); }
}
#keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
/* Add animation to "page content" */
.animate-bottom {
position: relative;
-webkit-animation-name: animatebottom;
-webkit-animation-duration: 1s;
animation-name: animatebottom;
animation-duration: 1s
}
#-webkit-keyframes animatebottom {
from { bottom:-100px; opacity:0 }
to { bottom:0px; opacity:1 }
}
#keyframes animatebottom {
from{ bottom:-100px; opacity:0 }
to{ bottom:0; opacity:1 }
}
#myDiv {
display: none;
text-align: center;
}
#myDi {
display: Float;
text-align: center;
}
Javascript:
var myVar;
function myFunction() {
myVar = setTimeout(showPage, 3000);
}
function showPage() {
document.getElementById("loader").style.display = "none";
document.getElementById("myDiv").style.display = "block";
document.getElementById("myDi").style.display = "block";
}
There are a number of approaches you can take. The current code says explicitly: "put #loader 200px below the top of the document" because of the top and position css properties. You could increase the top number to move it further down.
If you wanted to guarantee the loader is below the menu bar, even if the menu bar changes size, you could put it inside a relatively positioned div and remove the top property, which will make it display above the other content, but positioned relatively to the wrapper element (read more about positioning).
<!-- the navbar goes here -->
<div id="loader-wrapper">
<div id="loader" />
<div>
#loader-wrapper {
position: relative;
}
Another note about your code - make sure all your visible content is wrapped in your <body>. Right now your navbar is inside the <head>, which isn't valid.
#loader {
position: absolute;
left: 50%;
top: 200px;
transform: translate(-50%, 0);
}
Loader icon is loading in center of screen.
I see the HTML code. But The div in header should be placed in body tag.

How to create a zoom effect with function call in jquery

i have code in which when user clicks a link named zoom the an alert with a zoom effect is shown to user..
I want the same to happen when i click a button ...
when i try it to button click its not working.
How to achieve this?How to correct the code?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css'>
<style>
html,
body {
margin: 0;
padding: 10px;
-webkit-backface-visibility: hidden;
}
/* text-based popup styling */
.white-popup {
position: relative;
background: #FFF;
padding: 25px;
width: auto;
max-width: 400px;
margin: 0 auto;
}
/*
====== Zoom effect ======
*/
.mfp-zoom-in {
/* start state */
/* animate in */
/* animate out */
}
.mfp-zoom-in .mfp-with-anim {
opacity: 0;
transition: all 0.2s ease-in-out;
transform: scale(0.8);
}
.mfp-zoom-in.mfp-bg {
opacity: 0;
transition: all 0.3s ease-out;
}
.mfp-zoom-in.mfp-ready .mfp-with-anim {
opacity: 1;
transform: scale(1);
}
.mfp-zoom-in.mfp-ready.mfp-bg {
opacity: 0.8;
}
.mfp-zoom-in.mfp-removing .mfp-with-anim {
transform: scale(0.8);
opacity: 0;
}
.mfp-zoom-in.mfp-removing.mfp-bg {
opacity: 0;
}
</style>
</head>
<body>
<div class="links">
<div class id="inline-popups">
Zoom
<button onClick="#test-popup" data-effect="mfp-zoom-in">test</button>
</div>
</div>
<!-- Popup itself -->
<div id="test-popup" class="white-popup mfp-with-anim mfp-hide">Game completed sucessfull</div>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js'></script>
<script src="js/index.js"></script>
</body>
</html>
Try the below
var theControl = $("#test-popup");
$('#clickMe').magnificPopup({
items: {
src: theControl,
},
type: 'inline',
mainClass: 'mfp-with-zoom', // this class is for CSS animation below
zoom: {
enabled: true, // By default it's false, so don't forget to enable it
duration: 300, // duration of the effect, in milliseconds
easing: 'ease-in-out', // CSS transition easing function
// The "opener" function should return the element from which popup will be zoomed in
// and to which popup will be scaled down
// By defailt it looks for an image tag:
}
});
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.css'>
<style>
html,
body {
margin: 0;
padding: 10px;
-webkit-backface-visibility: hidden;
}
/* text-based popup styling */
.white-popup {
position: relative;
background: #FFF;
padding: 25px;
width: auto;
max-width: 400px;
margin: 0 auto;
}
/*
====== Zoom effect ======
*/
.mfp-zoom-in {
/* start state */
/* animate in */
/* animate out */
}
.mfp-zoom-in .mfp-with-anim {
opacity: 0;
transition: all 0.2s ease-in-out;
transform: scale(0.8);
}
.mfp-zoom-in.mfp-bg {
opacity: 0;
transition: all 0.3s ease-out;
}
.mfp-zoom-in.mfp-ready .mfp-with-anim {
opacity: 1;
transform: scale(1);
}
.mfp-zoom-in.mfp-ready.mfp-bg {
opacity: 0.8;
}
.mfp-zoom-in.mfp-removing .mfp-with-anim {
transform: scale(0.8);
opacity: 0;
}
.mfp-zoom-in.mfp-removing.mfp-bg {
opacity: 0;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js"></script>
<button id="clickMe" data-effect="mfp-zoom-in">test</button>
<div id="test-popup" class="white-popup mfp-with-anim mfp-hide">Game completed sucessfully</div>
You need to create a function that the onclick attribute will trigger. In that function, you can do the zoom logic that you prefer.
<button onclick="zoomLogic" data-effect="mfp-zoom-in">test</button>
Inside your script tag or in your script:
function zoomLogic() {
//Grab the element you wish the zoom effect to take place and do your logic
}

Make div float in and out by a button

I am having problems with making my div float in from the right to exactly 50% of the screen and i cant seem to figure it out why it won't work.
myFunction = function() {
var divPosition = $(".FadeIn").offset();
alert("Position: " + divPosition.left);
if (divPosition.right < '200%') {
$(".FadeIn").animate({
right: '50%'
}, 1000);
} else {
$(".FadeIn").animate({
right: '100%'
}, 1000);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<input type="button" class="btn btn-primary" name="FadeButton" value="Lees meer..." onclick="myFunction()" />
</div>
<div class="FadeIn">
Test
</div>
It should float in from the right to the middle (at exactly 50%), but it does nothing at all. And i can't figure out why.
https://jsfiddle.net/mbqxch2d/1/
Try this
Full Working Example JS-Fiddle
Includes also if user clickoutside and close button. If i missed something, write comment.
If you want also an verticle centered box, just update my animation:
$moreSocialsContainer.fadeIn().animate({
right: '50%',
'margin-right': (((1 - $moreSocialsContainer.outerWidth(true)) + 1) / 2) + 'px',
top: '50%',
'margin-top': (((1 - $moreSocialsContainer.outerHeight(true)) + 1) / 2) + 'px'
});
You must set the CSS position property for the element to relative, fixed, or absolute to manipulate or animate its position. For example, you can add the the following attribute to your div element: style="position: absolute;". Then, use window innerWidth property to float the element to the middle of the screen.
<script type="text/javascript">
function myFunction() {
$(".FadeIn").animate({
left: this.innerWidth / 2
}, 1000);
}
</script>
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
function showhide(){
$("#move").toggleClass("move");
};
</script>
<style>
body {
overflow: hidden;
}
.move {
width: 300px;
height: 100px;
background-color: red;
position: absolute;
-webkit-animation-name: animate;
-webkit-animation-duration: 1s;
-webkit-animation-delay: 0.1s;
animation-name: animate;
animation-duration: 1s;
animation-delay: 0.1s;
right:-50%;
animation-iteration-count: 1;
animation-fill-mode: forwards;
}
#-webkit-keyframes animate {
0% {right-50%;transform: translate(-50%, 0);}
100% {right: 50%;transform: translate(50%, 0);}
}
#keyframes animate {
0% {right-50%;transform: translate(-50%, 0);}
100% {right: 50%;transform: translate(50%, 0);}
}
</style>
</head>
<body>
<div id="move"></div>
<button onclick="showhide()">Click to Show</button>
</body>
</html>

Categories