javascript - Position a pop-up div relative to the link -
I am facing a problem I have 10 images in a page, each clicking on a pop up Will be displayed and the content of the clicked image is loaded from the database and it is shown in the div (pop up).
This is the first group of images (first line). But when I click on the second and third sets of image lines. Pop up opens up, but I have to scroll all the way and see pop up and its contents. (Since the image is at the bottom and displays the pop at the top of the page)
I created the situation and tried the following: Fixed! Important (View part I was partially successful in making popup center center.) But if the pop-up content is higher than the viewport height, then the remaining content is hidden and there is no option to scroll down to see more information. .)
Please refer to this image for more clarity < / P>
javascript
// viewport internal height $ (diarrhea Waze) to bring the height of pop-ups based on .ready (function () {function setHyight () {windowHeight = $ (window). WinnerHeight (); $ ('# panelpopup'). CSS ('height', WindowHigh);} SetHyot (); $ (Window). Reset (function () {setHeight ();});});
css
#panelpopup {max-width: 800px; Height: Auto! Important; Text-align: center; Background color: #FFF! Important; Border: Solid 1px # 333; Status: Sure! Important; // I tried the first time, but pop-up comes on top: 20%; Left: 50%; Margin: 0 px 0-400 px; Border-radius: 6px; Z-index: 100100! Important; }
HTML
& lt; Div id = "panelpopup-wrap" & gt; & Lt ;! - This is a transparent area around pop up - - & gt; & Lt; / Div & gt; & Lt; Div id = "panelpopup" & gt; & Lt ;! - Dynamic content goes here - & gt; & Lt; / Div & gt;
>
I dug a very old script that could serve you. It scrolls the window to the bottom right corner of the referenced element.
Can do this with some refinement (it was too long ;-) But it still works. Function CoverDiv (O) {var WH, ww; Var ps = document.getElementById (o) .getBoundingClientRect (); If (type window.innerWidth == 'number') {wh = window.innerHeight; Ww = window.innerWidth; } And if (document.documentElement & amp; amp; document.documentElement.clientWidth || document.documentElement.clientHeight)) {wh = document.documentElement.clientHyight; Ww = document.documentElement.clientWidth; } Other {return false; } Var diffH = wh - ps.bottom; Var diffW = ww - ps.right; DiffH = (diffH & lt; 10)? (20 - diffH): 0; DiffW = (diffW) & lt; 10? (30 - diffW): diffW = 0; Window. ScrollBy (diffW, diffH); }
Call it only with the id of the element.
Comments
Post a Comment