You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$("#prospects_form").submit(function(e){e.preventDefault();// prevent page reload on form submit});
Get scroll direction
// method 1 (for me only this worked stable)varlastScrollTop=0;// Or use body as css selector$(window).scroll(function(event){varst=$(window).scrollTop();if(st>lastScrollTop){// downscroll code}else{// upscroll code}lastScrollTop=$(window).scrollTop();});//method 2varlastScrollTop=0;$(window).scroll(function(event){varst=$(this).scrollTop();if(st>lastScrollTop){// downscroll code}else{// upscroll code}lastScrollTop=st;});
$.when($.getScript("js/headerbig.js"),$.getScript("js/menubar.js"),$.Deferred(function(deferred){$(deferred.resolve);})).done(function(){console.log('Scripts Load was performed.');});
Get path of element (css selector)
// Method #1jQuery.fn.getSelector=function(){if($(this).attr('id')){return'#'+$(this).attr('id');}if($(this).prop("tagName").toLowerCase()=='body')return'body';varmyOwn=$(this).attr('class');if(!myOwn){myOwn='>'+$(this).prop("tagName");}else{myOwn='.'+myOwn.split(' ').join('.');}return$(this).parent().getSelector()+' '+myOwn;}console.log('path: '+$(".owl-carousel .owl-item").getSelector());// Method #2functiongetSelector(el){var$el=jQuery(el);varselector=$el.parents(":not(html,body)").map(function(){vari=jQuery(this).index();i_str='';if(typeofi!='undefined'){i=i+1;i_str+=":nth-child("+i+")";}returnthis.tagName+i_str;}).get().reverse().join(" ");if(selector){selector+=" "+$el[0].nodeName;}varindex=$el.index();if(typeofindex!='undefined'){index=index+1;selector+=":nth-child("+index+")";}returnselector;}console.log('path: '+getSelector($(".owl-carousel .owl-item")));// If you want to get the nth child use $(this).index()$(elImageCSS).hover(function(){constselector=`${elImageCSS}:nth-child(${$(this).index()})`console.log(selector)},function(){constselector=`${elImageCSS}:nth-child(${$(this).index()})`console.log(selector)})
each loop
$(".owl-carousel .owl-item").each(function(){});
POST JSON to PHP file
letjson={email: emailInput,subject: subjectInput,message: messageInput,token: grecaptcha.getResponse()};$.post("php/contact.php",json,function(r){console.log('result after form submit:'+r);if(r==1){alert('Thanks for posting comment.')}else{alert('error..')}});
clone
// you can clone a element and then you got the element duplicated in DOM. If needed you can delete the first one after..$('#menubar-contact').clone(true).insertAfter($('#menubar-contact'));// $('#menubar-contact').remove();
$.fn.isInViewport=function(){varelementTop=$(this).offset().top;varelementBottom=elementTop+$(this).outerHeight();varviewportTop=$(window).scrollTop();varviewportBottom=viewportTop+$(window).height();returnelementBottom>viewportTop&&elementTop<viewportBottom;};$('.swiper').isInViewport()// returns true or false