Skip to main content

JavaScript Codes

Javascript Codes

Use this for Add Class on menu links using Javascript

   
   (function(){
      var el = document.querySelectorAll('.custom-menu-primary a')
      el.forEach(function(e){
      e.classList = e.textContent.toLowerCase().replace(/[^a-zA-Z0-9\.-]+/g,"");
      })
   })();
   
   

Add Class on Scroll using Varible Height

   
   (function() {
       let _body = document.getElementsByTagName('body');
       window.addEventListener('scroll', function() {
           _top = window.scrollY;
           if (_top > 100) {
               _body[0].classList.add("fadIn");
           } else {
               _body[0].classList.remove("fadIn")
           }
       });
   })();
   
   

Add Class on Scroll using Varible Height

   
   (function() {
       let _body = document.getElementsByTagName('body');
       let herderHeight = document.querySelector('.header-container-wrapper').scrollTop;
       window.addEventListener('scroll', function() {
           _top = window.scrollY;
           if (_top > herderHeight) {
               _body[0].classList.add("fadIn");
           } else {
               _body[0].classList.remove("fadIn")
           }
       });
   })();
   
   

Back To Top

   
   function scrollToTop(scrollDuration) {
    var scrollStep = -window.scrollY / (scrollDuration / 15);
    var scrollInterval = setInterval(function() {
        if (window.scrollY != 0) {
            window.scrollBy(0, scrollStep);
        } else {
            clearInterval(scrollInterval);
        }
    }, 15);
};

document.querySelector(".custom-back-to-top a").addEventListener("click", function(e) {
    e.preventDefault();
    scrollToTop(500);
});
   
   

Child Trigger

   
var childTirgger = document.querySelectorAll('.child-trigger')

childTirgger.forEach( function(ele){

 ele.addEventListener('click', function(e){

  var _style = window.getComputedStyle(ele.nextElementSibling, null).display;
  console.log(_style)

  if ( _style == 'none' ) {

   var sliblings = ele.parentNode.parentNode.children;
   for( var i =0; i < sliblings.length; i++ ){
    if (sliblings[i].classList.contains('has-submenu') ){
     sliblings[i].children[1].classList.remove('open-child');
     sliblings[i].children[2].style.display = 'none'
    }
   }

   ele.classList.add('open-child');
   ele.nextElementSibling.style.display = 'block'
  } else {

   ele.classList.remove('open-child');
   ele.nextElementSibling.style.display = 'none'
  }
 })

})
   
   

Comments

Popular posts from this blog

Default Parameters

Default Parameters A JavaScript function can have default parameter values. Using default function parameters, you can initialize formal parameters with default values. If you do not initialize a parameter with some value, then the default value of the parameter is undefined. Example 1 Without passing argument value function Hello(name) { console.log('Value Of Name parameter = ' + name ) } Hello(); Output Value Of Name parameter = undefined Example 2 passing argument value function Hello(name) { console.log('Value Of Name parameter = ' + name ) } Hello("Hello"); Output Value Of Name parameter = Hello Example 1 With Set Parameters Default vlaue // Add Name parameter default value is 'Hello World' check below function Hello( name='Hello World' ) { console.log('Value Of Name parameter = ' + name ) } // Calling without passing arguments show the default value Hello(); Output Value Of Name

Steps for install angular on your machine

Install Node Js from  https://nodejs.org/en/ .  after install node check installation is successful run command on CMD   node -v show the node version. Open Command Prompt Run as administrator and run command " npm install -g @angular/cli " when install angular cli shows some error and warning  ignore them.  After install the angular cli create the project in the C Drive when open command prompt run as administrator show the current path like this "C:\Windows\system32>" go to the root run "cd/" command  then enter go to the root "C:". Run command " ng new project-name "  like this "ng new angularApp " press enter.  go to our project folder "cd angularApp" press enter. run command " ng serve -o" this command run local server and shows your app on your browser http://localhost:4200. Extra command " https://github.com/angular/angular-cli/wiki"

Es6 Topics

Es6 Topics Let, Const Arrow Function Default Parameter Values Rest Parameter Spread Operator Template Literals Classes Class Definition Class Inheritance Class Inheritance, From Expressions Base Class Access Static Members Getter/Setter