I am using MooTools library. I want my fade in fade out effect on table id
<table id="myId"></table>
i have working click event
aNextCal.addEvent('click',function(){
//Click Event working here i want fade in fadeout code
this.showNextWeek();
}.bind(this));`
Please suggest
There is the default fade function to every element
document.id('myId').fade('out'); //hide
document.id('myId').fade('in'); //show
If you need something more complex to control the effect use Tween:
new Fx.Tween('myId', {
duration: 4000,
property: 'opacity',
onComplete: function(){
alert('hide');
}
}).start(0);
Mootools has a method fade, which is intended for fading elements in/out.
myElement.fade([how]);
how = ('in', 'out', 'show', 'hide', 'toggle', number)
Example of use:
// simple example
$('myId').fade('out');
// setting up element with options
$('myId').set( 'tween', {
duration: 400,
transition: 'quad:out'
});
$('myButton').addEvent('click', function(){
$('myId').fade( 'toggle' );
});
Related
Hi i use magnific pop up for an image gallery and i want to hide a div when the image zoom in and show it again when the image zoom out. This is my code :
$('.gallery-item').magnificPopup({
type: 'image',
gallery:{
enabled:true
},
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:
opener: function(openerElement) {
// openerElement is the element on which popup was initialized, in this case its <a> tag
// you don't need to add "opener" option if this code matches your needs, it's defailt one.
return openerElement.is('img') ? openerElement : openerElement.find('img');
}
}
});
Where should i put the the hide() and show() functions so they will be triggered same time with the magnific popup.
Don't use css for that, jQuery has built in functions for showing and hiding elements.
open: function(){
$(".main").hide();
},
close: function(){
$(".hidden-div").show();
}
Use this $( ".main" ).hide(); in your open function.
I have a menu with categories,
when I hover on a category a drop down show up
(I have already delayed the drop down to show up after 600 MS),
I want to know how to delay the hover event on the category too for 600 MS,
What is the best way and easiest way to achieve this using jquery?
jQuery('div.dropdown').hover(function() {
jQuery(this).find('.services-shortcut').addClass('active');
jQuery(this).find('.dropdown-menu').stop(true, true).delay(600).fadeIn(0);
}, function() {
jQuery(this).find('.services-shortcut').removeClass('active');
jQuery(this).find('.dropdown-menu').stop(true, true).delay(600).fadeOut(0);
});
I have made a bootply here http://www.bootply.com/lXioubaMre
You could use a basic CSS transition
.services-shortcut {
transition: all 0s .6s;
}
that runs immediately after a 600ms delay
Example: http://www.bootply.com/xppQzbvQ3P
If you choose to do this effect absolutely in javascript (but I wouldn't do it, just to keep off style from javascript) then apply the active class after a 600ms timeout, e.g.
jQuery('div.dropdown').hover(function() {
var $this = $(this);
setTimeout(function() {
$this.find('.services-shortcut').addClass('active');
}, 600);
$this.find('.dropdown-menu').stop(true, true).delay(600).fadeIn(0);
}, ...
If you use this approach then you should also clear the interval onmouseout
You can use hoverIntent jQuery plugin, which triggers functions based on client mouse movement. In your case the script would be simple, you can take a look at this Bootply:
function showMenu(e) {
jQuery(this).find('.services-shortcut').addClass('active');
jQuery(this).find('.dropdown-menu').show();
};
function hideMenu(e) {
jQuery(this).find('.services-shortcut').removeClass('active');
jQuery(this).find('.dropdown-menu').hide();
};
$("div.dropdown").hoverIntent({
over: showMenu,
out: hideMenu,
sensitivity: 3,
timeout: 800
});
$(".dropdown-menu a").hoverIntent({
over: function(){
$(this).addClass('active')
},
out: function(){
$(this).removeClass('active')
},
sensitivity: 3
});
I would use $.hoverDelay() plugin that does exactly that. It lets you configure the delay(s) for the 'in' and 'out' events like so:
$('div.dropdown').hoverDelay({
delayIn: 200,
delayOut:700,
handlerIn: function($element){
$element.css({backgroundColor: 'red'});
},
handlerOut: function($element){
$element.css({backgroundColor: 'auto'});
}
});
You can simply use jQuery.delay() method :
jQuery('div.dropdown').hover(function() {
alert("Action delayed");
jQuery(this).find('.services-shortcut').addClass('active');
jQuery(this).find('.dropdown-menu').stop(true, true).delay(600).fadeIn(0);
}, function() {
jQuery(this).find('.services-shortcut').removeClass('active');
jQuery(this).find('.dropdown-menu').stop(true, true).delay(600).fadeOut(0);
}).delay(600);
.dropdown{
background-color:red;
]
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="dropdown">
aaaa
</div>
That will wait for 600ms before executing your action, that's all you need.
How to make this button pulsate on jQuery mobile?
Are there problems with jQuery mobile because in my main application on some divs I can apply this pulsating effect and on other they just flicker, or fade in and out with interruptions or it jerky fades in and out.
html:
<button id="pulsate">I want to pulsate!</button>
JS:
$('#pulsate').on('click', function () {
pulsate("#pulsate");
});
function pulsate(element) {
$(element || this).animate({ opacity: 0 }, 500, function() {
$(this).animate({ opacity: 1 }, 500, pulsate); });
}
http://jsfiddle.net/alecstheone/zCUSK/
I only use jquery and jquerymobile... I noticed that if I disable jquerymobile in jsfiddle it works but I dont want this as I use jquerymobile in my application for other things...
Your code works fine but you've to make some changes to your script, As you're having a click event on the button but using jQuery mobile your button is wrapped around with span and divs(mainly because of jquery mobile css),
So you just have to traverse through that target div with .closest() to set your animation effect. Below is the small demo of your code with the desired effects.
$('#pulsate').on('click', function () {
pulsate(this); // Change here
});
function pulsate(element) {
$(element || this).closest("div.ui-btn").animate({
opacity: 0
}, 500, function () {
$(this).closest("div.ui-btn").animate({
opacity: 1
}, 500, pulsate);
});
}
Fiddle Example
This is the JavaScript code where when the user clicks on a new tab the contents on that page have a fade out effect by setting the opacity to 0. However the flaw is that all links from other pages are still clickable because it is only the opacity that has changed. What edit can I make to this code to keep the animation but hide the page content after the animation. (The same animation is when the page loads, but the opacity changes to 1.)
Code:
jQuery(document).ready(function() {
/* How to Handle Hashtags */
jQuery(window).hashchange(function(){
var hash = location.hash;
jQuery('a[href='+hash+']').trigger('click');
});
/* Main Navigation Clicks */
jQuery('.main-nav ul li a').click(function() {
var link = jQuery(this).attr('href').substr(1);
if ( !jQuery('section.content.show, section#' + link).is(':animated') ) {
jQuery('.main-nav ul li a').removeClass('active'); //remove active
jQuery('section.content.show').addClass('show').animate({'opacity' : 0}, {queue: false, duration: 1000,
complete: function() {
jQuery('a[href="#'+link+'"]').addClass('active'); // add active
jQuery('section#' + link).addClass('show').animate({'opacity' : 1}, {queue: false, duration: 1000});
}
});
}
});
});
Can you please re-paste the code with the edits as I am not the best at JS.
Can you post your css and html? It's hard to diagnosis this, but you could use .fadeOut() or .animate({"display":"none"}). I'm not sure if this is what you need, you'll have to post the rest of the code.
Simply set the display property to none in the callback (or just call hide()):
complete: function() {
jQuery(this).hide();
jQuery('a[href="#'+link+'"]').addClass('active'); // add active
jQuery('section#' + link).addClass('show').animate({'opacity' : 1}, {queue: false, duration: 1000});
}
Obviously you then have to take care to show the elements back again before animating them back in. ;-)
I was wondering how could we do this... Got nothing on my mind...
So my question Title might be confusing so here's full question.
How can we run our animation but skip animation of one class that contain .current...
This is menu animation so I don't want to animate current class as there's no point.
I was able to stop it by adding another class in CSS and using !important for height.
This way it looks like there's no animation but if I inspect elements, of course there is...
JS Code:
$("#topMenu li").mouseover(function(){
$(this).find('span').stop().animate({ height:'45px' }, { queue:false, duration:600, easing: 'easeOutBounce' });
});
$("#topMenu li").mouseout(function(){
$(this).find('span').stop().animate({ height:'0px' }, { queue:false, duration:600, easing: 'easeOutBounce' });
});
var currentPage = $('#topMenu span').hasClass('current');
if(currentPage === true) {
$('span.current').css('display', 'block');
}
So I am able to do this to look like there's no animation... But can we do it somehow so there's really no animation for the element that contain .current class in it ?
$(this).find('span:not(.current)').stop().animate...
You could add :not in the selector:
$('#topMenu li:not(.current)').mouseover(...)
If the class is being added dynamically after the event handlers have been added, move the check to be inside the handler:
$('#topMenu li').mouseover(function () {
if ($(this).hasClass('current')) return;
// etc
});