I want to write a code which can toggle two sentences fading in and fading out. But I want to toggle the sentences at the same location ie one text fades and the other starts coming in place of the first. In this case the sentences occur one below the other. Is there any way I can do this as in html content always comes one below the other.
This is the jquery script.
<script>
$(document).ready(function(){
$(function(){
$("#hide1").hide();
while(1)
{
$("#hide2").fadeOut(3000);
$("#hide1").fadeIn(3000);
$("#hide1").fadeOut(3000);
$("#hide2").fadeIn(3000);
}
});
});
</script>
Html
<p id="hide1"> Hide 1 <p>
<p id="hide2"> Hide 2 <p>
Demo Try like this make the queue and animate
$("#hide1").hide();
function hide1() {
$("#hide2").fadeIn(3000);
$("#hide2").fadeOut(3000, hide2);
}
function hide2() {
$("#hide1").fadeIn(3000);
$("#hide1").fadeOut(3000, hide1);
}
hide1();
OR Chaining
$("#hide1").hide();
function hide1() {
$("#hide2").fadeIn(3000).fadeOut(3000, hide2);
}
function hide2() {
$("#hide1").fadeIn(3000).fadeOut(3000, hide1);
}
hide1();
This code would react dynamically, and it does not need any changes even if you want to apply this effect for more than two p elements
$("p").hide();
function test(elem) {
elem.fadeIn(1000, function () {
elem.fadeOut(1000, function () {
test(elem.next('p').length ? elem.next('p') : $('p:first'));
});
});
}
test($('p:first'));
Try this:
setInterval(function () {
$('#hide1').fadeOut(1000, function () {
var $this = $(this);
$this.text($this.text() == 'Hide 2' ? 'Hide 1' : 'Hide 2');
$this.fadeIn(1000);
});
}, 3000);
Toggle the text within the setInterval
function.
i would like to query mysql database for some result using PHP and display the result in an alert dialog box using javascript. I can connect and query the database ontop on displaying the result in a ...
i would like to query mysql database for some result using PHP and display the result in an alert dialog box using javascript. I can connect and query the database ontop on displaying the result in a ...
For Angular's ng-repeat, I only saw inline equality filters. However, is it possible to inline inequalities as well? This fiddle illustrates my problem: Equality filter works: <div ng-controller="...
For Angular's ng-repeat, I only saw inline equality filters. However, is it possible to inline inequalities as well? This fiddle illustrates my problem: Equality filter works: <div ng-controller="...
I cannot for the life of me figure out what is going on here. I'll open a different browser to check if what I changed works, and maybe my other browser cached something, and it will work! But then I ...
I cannot for the life of me figure out what is going on here. I'll open a different browser to check if what I changed works, and maybe my other browser cached something, and it will work! But then I ...
I am working on jquerymobiles. I have to change the order of displaying div depending on change of value in select box html <select class="sel"> <option value="1">one</option>...
I am working on jquerymobiles. I have to change the order of displaying div depending on change of value in select box html <select class="sel"> <option value="1">one</option>...