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(); });
- put button outside both
div
s, below them. - using css, style button appears want (probably
position: absolute; bottom: 10px; right; 10px;
hard without knowing more page. - put local variable
ready
handler:var down = false;
- 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
Post a Comment