javascript - Smart positioning of menu relate to position of screen -
i want adjust menu screen position. want work in ie9. have row when right click on row show menu relate row.if click on last row want adjust menu top row. if click on first row screen want adjust menu bottom of row. fiddle
$( ".wrap" ).click(function() { $('.menu').hide(); var openpopmenu = $(this).find(".menu"); openpopmenu.show(); }); $(document).mouseup(function (e) { var openpopmenu = $(".menu"); if (!openpopmenu.is(e.target) && !openpopmenu.is(e.target) && openpopmenu.has(e.target).length == 0) { openpopmenu.hide(); } });
.wrap{ position: relative; padding: 10px; width: 450px; height:30px; border-bottom:1px solid #ccc; } .menu{ display:none; width: 210px; position: absolute; top: 10px; right: 10px; background-color: #fff; padding: 5px; z-index:1; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <h1> heading </h1> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div> <div class="wrap"> <div>lorem ipsum dolor sit amet, consectetuer adipiscing elit. aenean</div> <div class="menu"> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> <div>menu1</div> </div></div>
you can try use offsettop
of row , window.innerheight
correctly determine show menu or down relative row.
use position:absolute
or position:fixed
menu , top
/bottom
css styles positioning.
edit: sorry bug. not clienttop offsettop. additionally element.getboundingclientrect() method returns size of element , position relative viewport.
Comments
Post a Comment