侧栏广告简单插件
<script src="JS/jquery-1.6.2.min.js" type="text/javascript"></script>
( function($) { $.fn.barScroll = function(options) { /* width: 宽度 height: 高度 model: 模式 image,flash top: 距顶的距离 bargap:左边或右边的距离 bartype:挂靠模式 left,right link: 跳转链接 src: 文件链接 */ var defaults = { width: 100, height: 20, model: 'image', top: 100, bargap: 10, bartype: 'left', link: '#', src: '#' }; var opts = $.extend(defaults, options); var barScrollID = 'barScroll' + Math.round(Math.random() * 10000); var positiontype = $.browser.msie && $.browser.version < 7 ? "absolute" : "fixed"; if (opts.bartype != 'left' && opts.bartype != 'right') { opts.bartype = 'left'; } var str = ""; if (opts.model == "flash") { str += "<OBJECT codeBase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' type='application/x-shockwave-flash' width='" + opts.width + "' height='" + opts.height + "'>"; // str += "<PARAM NAME='Movie' VALUE='" + opts.src + "'>"; str += "<PARAM NAME='Src' VALUE='" + opts.src + "'>"; str += "<PARAM NAME='WMode' VALUE='Opaque'>"; str += "<PARAM NAME='Quality' VALUE='High'>"; str += "<PARAM NAME='AllowFullScreen' VALUE='false'>"; str += "<embed width='"+opts.widht+"' height='"+opts.height+"' src='"+opts.src+"' quality='High' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' wmode='opaque' allowscriptaccess='always' >" str += "</embed>"; str += "</object>"; } else { str += "<img src='" + opts.src + "' width='" + opts.width + "' height='" + opts.height + "'>"; } $("body").append("<a id='" + barScrollID + "' href='" + opts.link + "' style='position:" + positiontype + ";top:" + opts.top + "px;" + opts.bartype + ":" + opts.bargap + "px;z-index:999;' target='_blank'>" + str + "</a>"); if ($.browser.msie && $.browser.version < 7) { $(window).scroll( function() { $("#" + barScrollID + "").css("top", $(window).scrollTop() + opts.top + "px"); }) } $(window).resize( function() { $("#" + barScrollID + "").css("top", $(window).scrollTop() + opts.top + "px"); }) }; })(jQuery)
调用
$("body").barScroll({ width: 100, height: 248, model: 'image', top: 250, bargap: 0, bartype: 'left', link: 'index.html', src: '1.gif' }); $("body").barScroll({ width: 100, height: 248, model: 'flash', top: 250, bargap: 0, bartype: 'right', link: 'index.html', src: '1.swf' });