Animate (or fadeIn) a .text change - javascript

I am close to finishing a project but there is only one thing that I can't get to work, and that is how to animate this function:
$('.box').click(function(){
var description = $(this).find('.hide').text();
$('.description').text(description);
});
So what you see here is that I get a text from an element and place it into another element. But it is really rough it's just 'pop' and there it's. I tried serval things like putting .fadeIn() into the chain. Also I was thinking about doing it inside .animate() but I couldn't find a way to put it in. So my question is: Is there a way to animate this? or is it just simply not possible?
Thanks in advance :D

Related

Put an HREF in a DIV and give an scroll effect

I am trying to make a div to be an HREF. I have done it by using javascript...
var about = $('#about');
about.click(function(){
$(location).attr('href', '#quienes-somos');
});
So when I click the "about" div, I can go to the "quienes-somos" div.
However, I need to give the link a scroll effect. I was doing some research and I found that I could use the animate() method of jQuery, but I didn't really find out how to apply it to my script.
Thanks so much for any help you can give me!
Mauricio

How can I fadeIn/fadeOut of text using jQuery (or CSS)?

I'm building a random quote generator and would like to use the fadeIn/fadeOut function when switching between quotes when prompted by a button click. However I'm not sure how to target the text in jQuery, since I am printing the array directly from Javascript like this:
$('.show-quote').text(randomQuote);
Here is the project so far:
http://codepen.io/biancalelei/pen/vLeJVd
I think this is what you want: http://codepen.io/anon/pen/GoMGQL
$('.show-quote').fadeOut(300, function(){
$(this).text(randomQuote).fadeIn(300)
});
First, it will fade out in 300ms. When it is done the attached function will be executed. It changes the text and then fades it back in.
If you don't want the background to fade out as well, you can put the text in extra <div>: http://codepen.io/anon/pen/OMxEvK
You can use $('.show-quote').fadeIn() and $('.show-quote').fadeOut()
You can try this, first fadeOut 300ms and then fadeIn 300ms after that text print
$('.show-quote').fadeOut(300).fadeIn(300).text(randomQuote);
You can chain jQuery functions to achieve the functionality. Something like this:
$('.show-quote').hide().html(randomQuote).fadeIn(1000);
CodePen: http://codepen.io/anon/pen/wMrXyv

Jquery .load div content and find div id remove class

I need help understanding what I'm doing wrong. I'm loading a page and grabbing two divs using .load works great no issues. but then I want to find one of those divs and remove the bootstrap class and possibly add another class .addClass() howeve rI can't even get the removeClass to work. Am I doing this correctly?
$(document).ready(function() {
$("#siteloader").load( "/men/Maria-Brown #qvImage, #qvContent" );
$("#qvImage").removeClass(" .col-xs-12");
});
Awww yes I figured it out. because the main.js loads the popup and has it set to hidden until the popup is triggered. the
$("#qvImage").removeClass("col-xs-12");
needed to be added to the function inside the main.js now it works great.
thanks guys
I am not a really good understanding guy in all aspects of jquery, but I think I have one suggestion that you should check:
$(document).ready(function(){
$("#siteloader").load( "/men/Maria-Brown #qvImage, #qvContent", function(){
$("#qvImage").removeClass(" .col-xs-12");
} );
});
so this means that you run the "removeClass()" function AFTER the load is done. Try it.. I think this should help.
I can't write the comments yet, so I'm writing it as an Answer...

slideDown() slideUp() reversal

What I am after is a comand for doing the same as slideDown() slideUp(), but to work from the opposite direction.
So basicaly, slideUp() opens and slideDown() closes the div.
If it was only two div's , this would not be needed, but it will be with five or more in the same space.
If not possible, the only other option is if it is possible to "move" the div in the stack.
So on close, the div moves location in the html to above the one that has just opened. That way the illusion is still there.
EDIT:
From looking, though as sagested, the "Accordion" jQuery function was not what I was after, but a sub-class looks promissing.
If anyone into jQuery can help, would it be possible to use the "Sortable" option, but to sort on click.
As example, on click, move to top and then open.... ??
You mean you want the accordion effect?
Like this http://jqueryui.com/accordion/ ?
Ok it has been a while, but I wanted to update fore everyone's benefit.
So for my solution, was simple in the end. Just finding it was the task :-)
First is my JS code using jquery.
function contentToggle(v,w,x,y,z) {
$('#'+v).slideDown(300);
$('#'+w).slideUp(20);
$('#'+x).slideUp(20);
$('#'+y).slideUp(20);
$('#'+z).slideUp(20);
}
I did split the code in two myself, but this works.
Then on my page I make a link like this
Your link text for divID_1
Then repeat.....
But remember what is opening must be first in function line.
Function can be reused, so it is ok to have extra "slide up's" in it for what ever your need is.
Only the ones sent to function will run

JQuery: Why is hoverIntent not a function here?

I'm modifying some code from a question asked a few months ago, and I keep getting stymied. The bottom line is, I hover over Anchors, which is meant to fade in corresponding divs and also apply a "highlight" class to the Anchor. I can use base JQuery and get "OK" results, but mouse events are making the user experience less than smooth.
I load JQuery 1.3 via Google APIs.
And it seems to work. I can use the built in hover() or mouseover(), and fadeIn() is intact... no JavaScript errors, etc. So, JQuery itself is clearly "loaded". But I was facing a problem that it seemed everyone was recommending hoverIntent to solve.
After loading JQuery, I load the hoverIntent JavaScript. I've triple-checked the path, and even dummy-proofed the path. I just don't see any reasonable way it can be a question of path.
Once the external javascripts are (allegedly) loaded in, I continue with my page's script:
var $old=null;
$(function () {
$("#rollover a").hoverIntent(doSwitch,doNothing)
});
function doNothing() {};
function doSwitch() {
var $this = $(this);
var $index = $this.attr("id").replace(/switch/, ""); //extract the index number of the ID by subtracting the text "switch" from its name
if($old!=null) $old.removeClass("highlight"); //remove the highlight class from the old (previous) switch before adding that class to the next
$this.addClass("highlight"); //adds the class "highlight" to the current switch div
$("#panels div").hide(); //hide the divs inside panels
$("#panel" + $index).fadeIn(300); //show the panel div "panel + number" -- so if switch2 is used, panel2 will be shown
$old = $this; //declare that the current switch div is now "old". When the function is called again, the old highlight can be removed.
};
I get the error:
Error: $("#rollover a").hoverIntent is not a function
If I change to a known-working function like hover (just change ".hoverIntent" to ".hover") it "works" again. I'm sure this is a basic question but I'm a total hack when it comes to this (as you can see by my code).
Now, for all appearances, it SEEMS like either the path is wrong (I've zillion-checked and even put it on an external site with an HTTP link that I double-checked; it's not wrong), or the .js doesn't declare the function. If it's the latter, I must be missing a few lines of code to make the function available, but I couldn't find anything on the author's site. In his source code he uses a $(document).ready, which I also tried to emulate, but maybe I did that wrong, too.
Again, the weird bit is that .hover works fine, .hoverIntent doesn't. I can't figure out why it's not considered a function.
Trying to avoid missing anything... let's see... there are no other JavaScripts being called. This post contains all the Javascript the page uses... I tried doing it as per the author's var config example (hoverIntent is still not a function).
I get the itching feeling I'm just missing one line to declare the function, but I can't for the life of me figure out what it is, or why it's not already declared in the external .js file. Thanks for any insight!
Greg
Update:
The weirdest thing, since I'm on it... and actually, if this gets solved, I might not need hoverIntent solved:
I add an alert to the "doNothing" function and revert back to plain old .hover, just to see what's going on. For 2 of my 5 Anchors, as soon as I hover, doNothing() gets called and I see the alert. For the other 3, doNothing() correctly does NOT get called until mouseout. As you can see, the same function should apply for any Anchor inside of "rollover" div. I don't know why it's being particular.
But:
If I change fadeIn to another effect like slideDown, doNothing() correctly does NOT get called until mouseout.
when using fadeIn, doNothing() doesn't get called in Opera, but seems to get called in pretty much all other browsers.
Is it possible that fadeIn itself is buggy, or is it just that I need to pass it an appropriate callback? I don't know what that callback would be, if so.
Cheers for your long attention spans...
Greg
Hope I didn't waste too many people's time...
As it turns out, the second problem was 2 feet from the screen, too. I suspected it would have to do with the HTML/CSS because it was odd that only 2 out of 5 elements exhibited strange behaviour.
So, checked my code, dug out our friend FireBug, and discovered that I was hovering over another div that overlapped my rollover div. Reason being? In the CSS I had called it .panels instead of .panel, and the classname is .panel. So, it used defaults for the div... ie. 100% width...
Question is answered... "Be more careful"
Matt and Mak forced me to umpteen-check my code and sure enough I reloaded JQuery after loading another plugin and inserting my own code. Since hoverIntent modifies JQuery's hover() in order to work, re-loading JQuery mucked it up.
That solved, logic dictated I re-examine my HTML/CSS in order to investigate my fadeIn() weirdness... and sure enough, I had a typo in a class which caused some havoc.
Dumb dumb dumb... But now I can sleep.

Categories