By default if you specify a speed jquery adds a weird looking animation where it expands from the left end corner. I want it to just slide down. Is there a way to do that without importing something else like jquery UI ?
I'm looking something in the lines of :
$("test").show('slow', {animation:'slide'})
If there's no way, then what would be the lightest solution to do this?
Thanks
There are the slideDown, slideUp, and slideToggle functions native to jquery 1.3+, and they work quite nicely...
https://api.jquery.com/category/effects/
You can use slideDown just like this:
$("test").slideDown("slow");
And if you want to combine effects and really go nuts I'd take a look at the animate function which allows you to specify a number of CSS properties to shape tween or morph into. Pretty fancy stuff, that.
Use slidedown():
$("test").slideDown("slow");
You can also use a fadeIn/FadeOut Combo, too....
$('.test').bind('click', function(){
$('.div1').fadeIn(500);
$('.div2').fadeOut(500);
$('.div3').fadeOut(500);
return false;
});
Related
I currently use this JS animation plugin: http://www.2meter3.de/code/hoverFlow/ and the distinct result I like is the orange example. As far as I understand CSS transitions can only do the yellow example.
Is there a way to replicate this purely with CSS?
If not, then s there a way to use CSS transitions, but controlled by JS (jQuery) using the same principle (a good mix of both worlds)?
Maybe this could help my case: http://cortys.de/cssAnimate/
As far as I can see, that is not possible with CSS alone.
There is a trick to make the animation run to the end on hover by running another invisible animation on the element, but that doesn't work if you want to animate it back.
With a little bit of Javascript you can add a class to the element when the mouse hovers, then remove the class when the animation is complete:
$('div').mouseenter(function(){
$(this).addClass('animate');
}).on('transitionend', function(){
$(this).removeClass('animate');
});
Demo: http://jsfiddle.net/Guffa/oq83suw3/
However, it seems that the transition end event isn't always triggered, so the elements can get stuck with the class added to them. You can use a timeout to remove the class instead:
$('div').mouseenter(function(){
var e = $(this);
e.addClass('animate');
window.setTimeout(function(){
e.removeClass('animate');
}, 300);
});
Demo: http://jsfiddle.net/Guffa/u3c2knfj/
So I've finally cracked SVG animations (totally through cheating) and like most sites that use them if they're halfway down the page they begin automatically and you miss it, so how is it possible to trigger the animation on scroll to that div container?
Any help would be great,
Thanks!
You can use
beginElement() function to starts animations manually.
for this to work, you have to set the begin attribute of animate element to indefinite
a simple example would be something like
window.onscroll = function(){
var anime= document.getElementsByTagName('animate')[0];
// check for the amount of scroll
anime.beginElement();
}
You could also make use of beginElementAt()
read more about svg Animation Timing Control
side note: Can't be more accurate since you haven't shared much info or code samples, and not sure what you meant by 'cheating'
I'm having an unexpected effect and some other bugs when trying to use show/hide with mouseover and mouseout.
What I was trying to do is have a box (div) and when you would mouse over it, another box would appear and slide to the right.
Here's the fiddle for it
http://jsfiddle.net/XtXGR/
Now there's two problems with it. One is the flickering and the other is that it appears by growing from the top-left corner and what I want it to do is appear from the left.
Any help would be greatly be appreciated. Thanks
I think I know what causes the flickering from the similar questions but I still need help with the other issue. Thanks!
Oh also just so you know the context in which this will be used is on a page with a table of items and each item would be the object in the fiddle link I posted above.
The main issue is that moving over a different child element of the container will trigger a mouseout and mouseover combination, which is why you see the element expanding and collapsing. IE circumvented this with the mouseenter and mouseleave events, which act exactly like the CSS :hover.
Speaking of which, the jQuery hover function has this feature too. You should use that instead of mouseover and mouseout.
According to the show API, you should use the slide effect to get what you want.
Your final code should look like this: http://jsfiddle.net/XtXGR/28/
A couple things:
If you want to do a fadein/out this would be better:
$(document).ready(function(){
$("div.item_container").hover(function() {
$("div.item_body").fadeIn(500);
}, function() {
$("div.item_body").fadeOut(500);
});
});
Also, you should probably float the div .item_body to the left..
Demo: http://jsfiddle.net/lucuma/XtXGR/33/
How about using CSS3 transitions instead?
See this: http://jsfiddle.net/EVDj6/2/
Something like this? Using slide will give you the slide from default left effect.
$(document).ready(function(){
$("div.item_container").on('hover',function(){
$("div.item_body").toggle('slide',500);
});
});
http://jsfiddle.net/XtXGR/25/
There were many issues in your code. The href's were invalid and the floating of the elements was not 100% correct. One of the main issues was that you had display:none in your CSS. Bring that dispay:none out and of the CSS and put it inline on the item you want to show/hide. When its default state is "hide" then you need to bring the display:none inline.
Look at this fiddle to get a better idea of how to go about this with a bit more valid syntax:
http://jsfiddle.net/fH3EC/1/
I made something fast, you can go crazy with it :) The animation is pretty smooth, I hope it's useful for you.
http://jsfiddle.net/XtXGR/50/
I have a button that, when hovered over, shows a <span> that is otherwise hidden. What I'm trying to figure out is how to transition the button's expansion on :hover so it's more smooth. I tried using CSS3 transitions but couldn't quite get it down. Plus I don't know if that's the best solution anyway.
EDIT: I added some jQuery but must have something wrong. Here's the script I used, after reading a previous answer here (which I'll reference if I can find it again):
$('a:has(span)').hover(
function() { $('span', this).fadeIn(); },
function() { $('span', this).fadeOut(); },
);
I've created a Fiddle: http://jsfiddle.net/UYexr/. Can anyone help me out?
If I were you I would avoid using CSS3 simply because of its lack of support; given that I would probably stick to JS animation.
The best way I would see to do this is to make the span have display:inline-block; with a defined width. Then you can use a javascript animation library to animate the span's display.
Personally, I would go about using jQuery's animate method. Although there are plenty of js animation libraries...
I Like using Jquery and its companion Jquery Ui but can not find a way to animate background image over a certain period of time like 5 seconds.
I can not do something like:
$('sampleelement').animate({'background-image':'url(hello.jpg)'},5000);
Any ideas??
This is not possible like this. Css does not allow for backgound image manipulation like this. You should put in a div with the background behind your content and fade that in:
<div id='background_img' style='display:none; position:absolute;'><!-- position me behind the content!--><img ... /></div>
<div id='content'>YDADA</div>
$('#background_img').fadeIn(5000);
Use the jQuery Background-Position Animations plugin. See the demo.
Why don't you use an animated GIF?
Pim Jager's approach is about the closest you will get without an animated gif.
You could create multiple images and just replace one with another using setTimeout. It's kind of like emulating .gif, just gives more flexibility and quality.
What I did on Cheer Us Up is used basic javascript to change the background image --
$(function(){
curr = 0;
setTimout(changeBg(),200);
});
function changeBg() {
curr++;
document.body.style.backgroundPosition = curr + 20;
}
That is the basic idea. I didn't use jquery because I just wanted it to slowly slide by.
This is what you need: http://www.ovalpixels.com/bgImageTransition/