jquery.bgiframe.js 1.5 KB

123456789101112131415161718192021222324252627282930
  1. (function($){
  2. $.fn.bgIframe = $.fn.bgiframe = function(s) {
  3. // This is only for IE6
  4. if ( $.browser.msie && /6.0/.test(navigator.userAgent) ) {
  5. s = $.extend({
  6. top : 'auto', // auto == .currentStyle.borderTopWidth
  7. left : 'auto', // auto == .currentStyle.borderLeftWidth
  8. width : 'auto', // auto == offsetWidth
  9. height : 'auto', // auto == offsetHeight
  10. opacity : true,
  11. src : 'javascript:false;'
  12. }, s || {});
  13. var prop = function(n){return n&&n.constructor==Number?n+'px':n;},
  14. html = '<iframe class="bgiframe"frameborder="0"tabindex="-1"src="'+s.src+'"'+
  15. 'style="display:block;position:absolute;z-index:-1;'+
  16. (s.opacity !== false?'filter:Alpha(Opacity=\'0\');':'')+
  17. 'top:'+(s.top=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderTopWidth)||0)*-1)+\'px\')':prop(s.top))+';'+
  18. 'left:'+(s.left=='auto'?'expression(((parseInt(this.parentNode.currentStyle.borderLeftWidth)||0)*-1)+\'px\')':prop(s.left))+';'+
  19. 'width:'+(s.width=='auto'?'expression(this.parentNode.offsetWidth+\'px\')':prop(s.width))+';'+
  20. 'height:'+(s.height=='auto'?'expression(this.parentNode.offsetHeight+\'px\')':prop(s.height))+';'+
  21. '"/>';
  22. return this.each(function() {
  23. if ( $('> iframe.bgiframe', this).length == 0 )
  24. this.insertBefore( document.createElement(html), this.firstChild );
  25. });
  26. }
  27. return this;
  28. };
  29. })(jQuery);