javascript - Issue on Using One Switch Botton to Toggle Functions in jQuery -


i using 2 buttons slide , down page @ this sample as:

<div id="map"><button type="button" class="btn btn-default green goinfo">go info</button></div> <div id="info"> <button type="button" class="btn btn-default green gomap">go map</button></div> 

can please let me know how can reduce buttons do same job? :

 <button type="button" class="btn btn-default slider">switch view</button> 

jquery

jquery('body').css('overflow','hidden');       var viewheight = $('#map').height();    $('.goinfo').fadein();     $(window).scroll(function () {         if ($(this).scrolltop() < 100) {             $('.goinfo').fadein();         } else {             $('.goinfo').fadeout();         }     });       $(window).scroll(function () {         if ($(this).scrolltop() > 100) {             $('.gomap').fadein();         } else {             $('.gomap').fadeout();         }     });      $('.gomap').click(function () {         $("html, body").animate({             scrolltop: 0         }, 600);         return false;     });       $('.goinfo').click(function () {          $("html, body").animate({             scrolltop: viewheight         }, 600);         return false;     });      $( window ).resize(function() {     var mapheight = $('#mapview').height();  }); 

  1. put button outside both divs, below them.
  2. using css, style button appears want (probably position: absolute; bottom: 10px; right; 10px; hard without knowing more page.
  3. put local variable ready handler: var down = false;
  4. in button handler, this:

code:

if (down) {    down = false;    $('html, body').animate(...); } else {    down = true;    $('html, body').animate(...); } 

but honestly, think have less complicated , not problematically wordy, wouldn't change myself.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -