jquery.bgiframe.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Copyright (c) 2006 Brandon Aaron (http://brandonaaron.net)
  2. * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
  3. * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
  4. *
  5. * $LastChangedDate: 2007-02-18 22:09:54 -0600 (Sun, 18 Feb 2007) $
  6. * $Rev: 1379 $
  7. */
  8. /**
  9. * The bgiframe is chainable and applies the iframe hack to get
  10. * around zIndex issues in IE6. It will only apply itself in IE
  11. * and adds a class to the iframe called 'bgiframe'.
  12. *
  13. * It does take borders into consideration but all values
  14. * need to be in pixels and the element needs to have
  15. * position relative or absolute.
  16. *
  17. * NOTICE: This plugin uses CSS expersions in order to work
  18. * with an element's borders, height and with and can result in poor
  19. * performance when used on an element that changes properties
  20. * like size and position a lot. Two of these expressions can be
  21. * removed if border doesn't matter and performance does.
  22. * See lines 39 and 40 below and set top: 0 and left: 0
  23. * instead of their current values.
  24. *
  25. * @example $('div').bgiframe();
  26. * @before <div><p>Paragraph</p></div>
  27. * @result <div><iframe class="bgiframe".../><p>Paragraph</p></div>
  28. *
  29. * @name bgiframe
  30. * @type jQuery
  31. * @cat Plugins/bgiframe
  32. * @author Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
  33. */
  34. jQuery.fn.bgIframe = jQuery.fn.bgiframe = function() {
  35. // This is only for IE6
  36. if ( !(jQuery.browser.msie && typeof XMLHttpRequest == 'function') ) return this;
  37. var html = '<iframe class="bgiframe" src="javascript:false;document.write(\'\');" tabindex="-1" '
  38. +'style="display:block; position:absolute; '
  39. +'top: expression(((parseInt(this.parentNode.currentStyle.borderTopWidth) || 0) * -1) + \'px\'); '
  40. +'left:expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth) || 0) * -1) + \'px\'); '
  41. +'z-index:-1; filter:Alpha(Opacity=\'0\'); '
  42. +'width:expression(this.parentNode.offsetWidth + \'px\'); '
  43. +'height:expression(this.parentNode.offsetHeight + \'px\')"/>';
  44. return this.each(function() {
  45. if ( !jQuery('iframe.bgiframe', this)[0] )
  46. this.insertBefore( document.createElement(html), this.firstChild );
  47. });
  48. };