Tuesday, September 25, 2018

jQuery: quick reference codes

//check if element is hidden (display: "none")
if($('a.click').is(":visible")) {
 $('.my-block').show();
} else {
 $('.my-block').hide();
}
//toggle function
$('.megamenu').toggle(function() {
   // code here
}, function() {
  //code here
});
//set timeout
$('.close-mobile-search').click(function(){
   setTimeout(hideDropDown, 500);
});
 
//or

window.setTimeout(function(){
        $this.addClass('finsihed');
}, 10000); //<-- Delay in milliseconds
 
//scroll based function
$(window).on("scroll", function() {
   //code goes here
});
//trigger after ajax call is executed
//inside the specified element
//execute on async news comments
$('.comments > .ajax-comment-wrapper').ajaxComplete(function(){
   tooltipLoad();
   tooltipActions();
});
//prevent event to be fired more than once
jQuery('a.click').click(function(evt){
  evt.stopImmediatePropagation();
});
//fade out form upon scrolling down
$(".text").css({
  'opacity' : 1-(($(this).scrollTop())/350)
});

No comments:

Post a Comment