jQuery图片漂浮插件 就是某个层在屏幕上弹啊弹的,各大清理广告软件都清不掉的哦!
以下是代码:(自己封装js)
- /*
- * jQuery Plugins imgFloat v1011
- * 使用说明:
- * speed //元素移动速度
- * xPos //元素一开始左距离
- * yPos //元素一开始上距离
- * $('#div1').imgFloat({speed:30,xPos:10,yPos:10});
- * $('#div2').imgFloat(); //不给参数默认(speed:10,xPos:0,yPos:0)
- */
(function($) {
- jQuery.fn.imgFloat = function(options) {
- var own = this;
- var xD = 0;
- var yD = 0;
- var i = 1;
- var settings = {
- speed: 10,
- xPos: 0,
- yPos: 0
- };
- jQuery.extend(settings, options);
- var ownTop = settings.xPos;
- var ownLeft = settings.yPos;
- own.css({
- position: "absolute",
- cursor: "pointer"
- });
- function imgPosition() {
- var winWidth = $(window).width() - own.width();
- var winHeight = $(window).height() - own.height();
- if (xD == 0) {
- ownLeft += i;
- own.css({
- left: ownLeft
- });
- if (ownLeft >= winWidth) {
- ownLeft = winWidth;
- xD = 1;
- }
- }
- if (xD == 1) {
- ownLeft -= i;
- own.css({
- left: ownLeft
- });
- if (ownLeft <= 0) xD = 0;
- }
- if (yD == 0) {
- ownTop += i;
- own.css({
- top: ownTop
- });
- if (ownTop >= winHeight) {
- ownTop = winHeight;
- yD = 1;
- }
- }
- if (yD == 1) {
- ownTop -= i;
- own.css({
- top: ownTop
- });
- if (ownTop <= 0) yD = 0;
- }
- }
- var imgHover = setInterval(imgPosition, settings.speed);
- own.hover(function() {
- clearInterval(imgHover);
- },
- function() {
- imgHover = setInterval(imgPosition, settings.speed);
- });
- }
- })(jQuery);
神呐
应用到图片上
html
<div id=img><img src="1.jpg"></div> 或者<img id=img src="1.jpg">
js
$('#img).imgFloat({speed:30,xPos:10,yPos:10});
$('#img).imgFloat(); //不给参数默认(speed:10,xPos:0,yPos:0)
前提是要加jq库和上的代码 如果不清楚jq用法的可以站内信 或者百度