jeudi 13 août 2015

Combine two specific javascript functions into one function for desired effect?

How can I combine two specific javascript functions into one function for the desired effect? or if anyone has a different solution I am open to it.

Here is the JS/Jquery to make the page scroll to an href anchor url using jquery.easing.1.3.js

    $(function() {
           $('a').bind('click',function(event){
                var $anchor = $(this);

                $('html, body').stop().animate({
                    scrollTop: $($anchor.attr('href')).offset().top
                }, 1500,'easeInOutExpo');
                event.preventDefault();
            });
        });

Here is an older JS to hide/show a series of divs only allowing one div to show at any given time.

function NavigateSpecs(thechosenspec) {
    var SPEC = document.getElementsByTagName("div");
    for(var x=0; x<SPEC.length; x++) {
        name = SPEC[x].getAttribute("name");
        if (name == 'SPEC-2') {
              if (SPEC[x].id == thechosenspec) {
                    if (SPEC[x].style.display == 'block') {
                          SPEC[x].style.display = 'none';
                    }
                    else {
                          SPEC[x].style.display = 'block';
                    }
              }else {
                    SPEC[x].style.display = 'none';
              }
        }
     }
    }

I need to combine these two functions so upon clicking a link the browser will scroll to the desired anchor like the first JS function and show the specific div while hiding any other div with the similar id structure.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire