Jquery 飘窗
1 <script type="text/javascript" src="jquery.js"></script> 2 <script type="text/javascript"> 3 (function($) { 4 $.fn.floatAd = function(options) { 5 var defaults = { 6 imgSrc:"", 7 url:"", 8 openStyle: 1, 9 speed: 30 10 }; 11 var options = $.extend(defaults, options); 12 var _target = options.openStyle == 1 ? "target='_blank'": ''; 13 var html = "<div id='float_ad' style='position:absolute;left:0px;top:0px;z-index:1000000;cleat:both;'>"; 14 html += " <a href='" + options.url + "' " + _target + "><img src='" + options.imgSrc + "' border='0' class='float_ad_img'/></a>"; 15 html += "<div id='close_f_ad' style='position:absolute;width:30px;height:16px;top:-18px;right:0px;cursor:pointer;float:right;font-size:14px'>关闭</div></div>"; 16 $('body').append(html); 17 function init() { 18 var x = 0, 19 y = 0; 20 var xin = true, 21 yin = true; 22 var step = 1; 23 var delay = 10; 24 var obj = $("#float_ad"); 25 obj.find('img.float_ad_img').load(function() { 26 var float = function() { 27 var L = T = 0; 28 var OW = obj.width(); 29 var OH = obj.height(); 30 var DW = $(document).width(); 31 var DH = $(document).height(); 32 x = x + step * (xin ? 1 : -1); 33 if (x < L) { 34 xin = true; 35 x = L; 36 } 37 if (x > DW - OW - 1) { 38 xin = false; 39 x = DW - OW - 1; 40 } 41 y = y + step * (yin ? 1 : -1); 42 if (y > DH - OH - 10) { 43 yin = false; 44 y = DH - OH - 10; 45 } 46 if (y < T) { 47 yin = true; 48 y = T; 49 } 50 var left = x; 51 var top = y; 52 obj.css({ 53 'top': top, 54 'left': left 55 }) 56 }; 57 var itl = setInterval(float, options.speed); 58 $('#float_ad').mouseover(function() { 59 clearInterval(itl) 60 }); 61 $('#float_ad').mouseout(function() { 62 itl = setInterval(float, options.speed) 63 }) 64 }) 65 } 66 init(); 67 $('#close_f_ad').click(function(){ 68 $('#float_ad').css('display','none'); 69 clearInterval(itl); 70 }); 71 } 72 })(jQuery); 73 74 $(document).ready(function() { 75 $(function() { 76 $("body").floatAd({ 77 imgSrc: 'http://www.customs.gov.cn/Portals/114/images/zxftyg2014010601.jpg', 78 url: 'http://www.customs.gov.cn/tabid/66651/Default.aspx' 79 }); 80 }) 81 }); 82 </script>