jquery - JavaScript screen positions after collapse -


im tried hide div tag using javascript,but when collapse, how screen exact dive in screen position?

javascript , css , html follows

  // hide elements in dom have class of "box"      $('.box').hide();        // make sure elements class of "clickme" visible , bound      // click event toggle "box" state      $('.clickme').each(function () {          $(this).show(0).on('click', function (e) {              // needed if using anchor target "box"   elements              e.preventdefault();                // find next "box" element in dom              $(this).next('.box').slidetoggle('fast');          });      });        $("#submit").click(function (e) {          e.preventdefault();          $("#box1").slidetoggle('fast');          $("#box2").slidetoggle('fast');      });
body {      font: 12px/16px sans-serif;      margin: 10px;      padding: 0;      }         .clickme {      background-color: #eee;      border-radius: 4px;      color: #666;      display: block;      margin-bottom: 5px;      padding: 5px 10px;      text-decoration: none;}        }        .clickme:hover {      text-decoration: underline;      }        .box {      background-color: #ccc;      border-radius: 4px;      color: #333;      margin: 5px 0;      padding: 5px 10px;      width: auto;      }
<a href="#" class="clickme">menu 1</a>      <span><span class="labeltext"><span></span>number 1</span>      </span>      <input type="text" value="" maxlength="50">      <br/>      <span><span class="labeltext"><span></span>number 2</span>      </span>      <input type="text" class="inputclmsize1" value="" maxlength="50" aria-invalid="false">      <br>      <a id="submit" href="#">submit</a>      </div>      <a href="#" class="clickme">menu 2</a>      <div id="box2" class="box">          lorem ipsum dummy text of printing , typesetting industry. lorem ipsum has been industry's standard dummy text ever since 1500s, when unknown printer took galley of type , scrambled make type specimen book. has survived not 5 centuries, leap electronic typesetting,      </div>

i added jsfiddle more text data. want is, after clicked menu 1, there end of submit link. when click submit link in menu 1, automatically menu 2 open. not open correct position screen.i want show menu 2 on screen start position. how position this? you. can view this.

http://jsfiddle.net/rn4qdyue/14/

you can use scrolltop of parent , position @ top position of element want @ top. you'll have factor other values such offset of parent , margins if want precise. call after slide animation. this:

       $(this).next('.box').slidetoggle('fast', function () {             $(this).parent().animate({                 scrolltop: $(this).position().top - $(this).parent().offset().top - 15             })         }) 

see fiddle: http://jsfiddle.net/k5o3bl69/1/


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -