javascript - Anchor dropdown menu for options with hidden content -


i have drop down menu add anchors to. drop down has 4 options hidden on start. when option clicked, section visible. drop down menu have content above , need page move down when option clicked , becomes visible. how add anchors these options?

i'm not versed in javascript, have:

<html>     <head>     <meta charset="utf-8">      <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>          <script>             $(document).ready(function(){                 $('#purpose').on('change', function() {                     if ( this.value == '0'){                         $("#value0").show();                     } else {                         $("#value0").hide();                     }                      if ( this.value == '1'){                         $("#value1").show();                     } else {                         $("#value1").hide();                     }                      if ( this.value == '2'){                         $("#value2").show();                     } else {                         $("#value2").hide();                     }                      if ( this.value == '3'){                         $("#value3").show();                     } else {                         $("#value3").hide();                     }                 });             });         </script>     </head>     <body>      <!--drop down-->     <p><select id="purpose">     <option value="0">&nbsp;</option>     <option value="1">1 column w/big hero</option>     <option value="2">1 column w/s-curve</option>     <option value="3">1 column; linear</option>     </select></p>     <!--end drop down-->      <table width="100%" height="1000" cellspacing="0" cellpadding="0" border="0" align="left">         <tbody>             <tr>                 <td>&nbsp; &nbsp;</td>             </tr>         </tbody>     </table>        <!--default value 0-->     <div id="value0" style="display:block;"></div>     <!--end default value 0-->       <!--option 1-->     <div align="center" id="value1" style="display:none;">content value 1</div>     <!--end option 1-->        <!--option 2-->     <div align="center" id="value2" style="display:none;">content value 2</div>     <!--end option 2-->       <!--option 3-->     <div align="center" id="value3" style="display:none;">content value 3</div>     <!--end option 3-->      </body> </html> 

you can top level of item fetching.

var valuetop = $("#value0").offset().top; // offset of item $(window).scrolltop( valuetop ); // set window's scroll position 

in example:

$('#purpose').on('change', function() {     if ( this.value == '0'){         $(value0).show();         var vtop = $("#value0");         var valuetop = vtop.offset().top         $(window).scrolltop( valuetop );         } else {         $("#value0").hide();     } }) 

you can animate scrolling:

$('#purpose').on('change', function() {     if ( this.value == '0'){         $(value0).show();         var vtop = $("#value0");         var valuetop = vtop.offset().top         $('html, body').animate({scrolltop: valuetop},500);     } else {         $("#value0").hide();     } }) 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -