css - Prevent page jump from :target selector -
so have modal pops using css :target selector. however, page jumps anchor when clicked. prevent page jumping :target selector. how can this?
<a href="#openmodal">info</a> <div id="openmodal" class="modaldialog">
css:
.modaldialog { position: absolute; pointer-events: none; z-index: 99999; opacity:0; } .modaldialog:target { opacity:1; pointer-events: auto; } .modaldialog > div { width: 900px; height: 506px; position: relative; background: rgba(0,0,0,0.9); }
make .modaldialog
position: fixed
instead of absolute
. cause positioned @ wherever page scrolled.
a more complete example: http://codepen.io/mblase75/pen/xbrnev
(there's other trickery involved in codepen demo -- adding target 'close' button on modal fixed
keeps page scrolling when modal closed, , changing z-index
of modal -1
100
(or other suitably large integer) keep blocking clicks right after close it.)
Comments
Post a Comment