Reputation: 693
Hi i am trying to animate to the right but it doesn't seem to be working but opacity change does work in the same function?
$(document).on("click touchstart tap", ".buttonchat", function () {
$('.message').each(function(i) {
delay =(i)*500;
$(this).delay(delay).animate({
opacity: 0,
right: "-150px"
},1000, function() {
// Animation complete.
});
});
});
as you can see in this pen animating to the right does nothing but changing opacity works what's happening? pen: https://codepen.io/uiunicorn/pen/YzZXwJp
thanks in advance
Upvotes: 0
Views: 152
Reputation: 469
Your messages span will have to have the position: absolute
property...
<span class="message" style="width: 18.2105rem; height: 1.26316rem; opacity: 1; position:absolute;">Hello! 👋 I hope you're having a good night</span>
Here's a working pen: https://codepen.io/paulmartin91/pen/RwpPaPL
Here's the explanation from W3 Schools:
By default, all HTML elements have a static position, and cannot be moved. To manipulate the position, remember to first set the CSS position property of the element to relative, fixed, or absolute!
Upvotes: 2
Reputation: 355
In CSS file you should consider adding "." in the beginning. and Js file here below with corrections.
$(document).on("click touchstart tap", ".buttonchat", function () {
$('.message').each(function(i) {
delay =(i)*500;
$(this).delay(delay).animate({
"opacity": 0.20 ,
"right": "0px" , "top": "0px" , "background-color" : "green"
},1000, function() {
// Animation complete.
});
});
});
.message{
left: 0px;
position : absolute ;
}
.relative{ position : relative ; }
<button style="width: 200px; height: 100px" class="buttonchat"></button>
<div class="message-main relative">
<div class="message-hold">
<div class="messages">
<div
class="bubble cornered left"
style="
opacity: 1;
width: 19.2105rem;
height: 2.47368rem;
margin-top: 0px;
margin-left: 0px;
transform: scale(1);
"
>
<div class="loading" style="transform: translateX(0rem) scale(1)"
><b style="opacity: 0; transform: scale(0)">•</b
><b style="opacity: 0; transform: scale(0)">•</b
><b style="opacity: 0; transform: scale(0)">•</b></div
><div
class="message"
style="width: 18.2105rem; height: 1.26316rem; opacity: 1"
>Hello! 👋 I hope you're having a good night</div
>
</div>
<br />
<div
class="bubble cornered left"
style="
opacity: 1;
width: 15.7368rem;
height: 2.47368rem;
margin-top: 0px;
margin-left: 0px;
transform: scale(1);
"
>
<div class="loading" style="transform: translateX(0rem) scale(1)"
><b style="opacity: 0; transform: scale(0)">•</b
><b style="opacity: 0; transform: scale(0)">•</b
><b style="opacity: 0; transform: scale(0)">•</b></div
><div
class="message"
style="width: 14.7368rem; height: 1.26316rem; opacity: 1"
>I'm a junior interactive designer 😎</div
>
</div>
<br />
<div
class="bubble cornered left"
style="
opacity: 1;
width: 23.8947rem;
height: 2.47368rem;
margin-top: 0px;
margin-left: 0px;
transform: scale(1);
"
>
<div class="loading" style="transform: translateX(0rem) scale(1)"
><b style="opacity: 0; transform: scale(0)">•</b
><b style="opacity: 0; transform: scale(0)">•</b
><b style="opacity: 0; transform: scale(0)">•</b></div
>
<div
class="message"
style="width: 22.8421rem; height: 1.26316rem; opacity: 1"
>
which basically means I create cool looking websites 🤘
</div>
</div>
<br />
<div
class="bubble cornered left"
style="
opacity: 1;
width: 30.9474rem;
height: 2.47368rem;
margin-top: 0px;
margin-left: 0px;
transform: scale(1);
"
>
<div class="loading" style="transform: translateX(0rem) scale(1)"
><b style="opacity: 0; transform: scale(0)">•</b
><b style="opacity: 0; transform: scale(0)">•</b
><b style="opacity: 0; transform: scale(0)">•</b></div
><div
class="message"
style="width: 29.9474rem; height: 1.26316rem; opacity: 1"
>I have exactly 0 qualifications and mostly get by using stackoverflow
👀</div
>
</div>
<br />
<div
class="bubble cornered left"
style="
opacity: 1;
width: 20.3158rem;
height: 2.47368rem;
margin-top: 0px;
margin-left: 0px;
transform: scale(1);
"
>
<div class="loading" style="transform: translateX(0rem) scale(1)"
><b style="opacity: 0; transform: scale(0)">•</b
><b style="opacity: 0; transform: scale(0)">•</b
><b style="opacity: 0; transform: scale(0)">•</b></div
><div
class="message"
style="width: 19.3158rem; height: 1.26316rem; opacity: 1"
>Now I have your full confidence let's move on!</div
>
</div>
<br />
</div>
</div>
</div>
Upvotes: 1