Guest User

Untitled

a guest
Apr 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. //adding a close button to the overlay and bind a click on it to close the overlay
  2. $(document).ready(function() {
  3. var winWidth = $(window).width();
  4. var winHeight = $(window).height();
  5. var edgeSpace = 40;
  6. var iframeWidth = winWidth - edgeSpace * 2;
  7. var iframeHeight = winHeight - edgeSpace * 2;
  8.  
  9. $('#demo').click(function() {
  10. //add a close anchor inside the overlay div
  11. $('body').append('<div id="demoarea"><iframe src="'+$(this).attr('href')+'" width="'+iframeWidth+'" height="'+iframeHeight+'"></iframe><a href="#close" id="close"></a></div>');
  12.  
  13. $('#demoarea').css({
  14. 'position' : 'fixed',
  15. 'top' : edgeSpace+'px',
  16. 'left' : edgeSpace+'px',
  17. 'background' : 'white',
  18. 'max-height' : iframeHeight+'px',
  19. 'box-shadow' : '0 0 '+edgeSpace+'px black',
  20. '-moz-box-shadow' : '0 0 '+edgeSpace+'px black',
  21. '-webkit-box-shadow' : '0 0 '+edgeSpace+'px black',
  22. }).children('#close').css({ //style the close anchor
  23. 'position' : 'absolute', //make it position absolute to the overlay div
  24. 'top' : '-15px', //position it to top
  25. 'left' : '-15px', //and to left
  26. 'display' : 'block', //make it a block
  27. 'width' : '30px', //set width of background image
  28. 'height' : '30px', //and height
  29. 'background' : 'url(images/close.png)' //and the actual url of the background image
  30. }).click(function() { //bind a click on the close anchor
  31. $(this).parent().remove(); //remove the overlay div from the dom
  32. return false; //dont follow the link
  33. });
  34.  
  35. return false;
  36. });
  37. });
Add Comment
Please, Sign In to add comment