首頁 > web前端 > js教程 > 首頁圖片漂浮效果範例程式碼_javascript技巧

首頁圖片漂浮效果範例程式碼_javascript技巧

WBOY
發布: 2016-05-16 16:46:04
原創
1234 人瀏覽過
複製程式碼 程式碼如下:



function addEvent(obj, evtType, func, cap) {
cap = cap ||錯誤的;
if (obj.addEventListener) {
obj.addEventListener(evtType, func, cap);
回傳真;
} else if (obj. attachEvent) {
if (cap) {
obj.setCapture();
回傳真;
} else {
return obj.attachEvent("on" evtType, func);
return obj.attachEvent("on" evtType, func); }
} else {
回傳false;
}
}
function getPageScroll() {
var xScroll, yScroll;
if (self.pagef.page >xScroll = self.pageXOffset;
} else if (document.documentElement && document.documentElement.scrollLeft) {
xScroll = document.documentElement.scrollLeft;d.com >xScroll = document.body.scrollLeft;
}
if (self.pageYOffset) {
yScroll = self.pageYOffset;
} else if (document.documentElement &doct&opumentElement &doct.
yScroll = document.documentElement.scrollTop;
} else if (document.body) {
yScroll = document.body.scrollTop;
}
Scay ;
回傳陣列PageScroll;
}
function GetPageSize() {
var xScroll, yScroll;
if (window.innerHeight && window.scrollY) {
if (window.innerHeight && window.scrollY) {
if. .scrollWidth;
yScroll = window.innerHeight window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight) {
xScroll = documentth.sroll.Ldocument; = document.body.scrollHeight;
} else {
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var document.body.offsetHeight; }
var windowWido>var windowWg,window好> windowHeight; if (self.innerHeight) {
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.t. documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) {
windowWidth = document.body.clientWidth;; 🎜>}
if (yScroll pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
if (xxScidroll } else {
pageWidth = xScroll;
}
arrayPageSize = new Array(pageWidth, pageHeight, windowWidth, windowal;
var AdMoveConfig = new Object();
AdMoveConfig.IsInitialized = false;
AdMoveConfig.ScrollX = 0;
AdMoveConfig.Scroll = 0; AdMoveConfig.MoveHeight = 0;
AdMoveConfig.Resize = function () {
var winsize = GetPageSize();
AdMoveConfig.MoveWidth = winsize[2];fwinsize[2]; ;
AdMoveConfig.Scroll();
}
AdMoveConfig.Scroll = function () {
var winscroll = getPageScroll();
AdMoveConfig.ScrollX = winroll[0]; AdMoveConfig.ScrollY = winscroll[1];
}
addEvent(window, "resize", AdMoveConfig.Resize);
addEvent(window, "scroll", AdMoveConfig.Scroll);
funcdow, "scroll", AdMoveConfig.Scroll);
function (id) {
if (!AdMoveConfig.IsInitialized) {
AdMoveConfig.Resize();
AdMoveConfig.IsInitialized = true;
}
var objElementBydocum (idum);
obj.style.position = "絕對";
var W = AdMoveConfig.MoveWidth - obj.offsetWidth;
var H = AdMoveConfig.MoveHeight - obj.offsetHeight var rad = (Math.random() 1) * Math.PI / 6;
var kx = Math.sin(rad), ky = Math.cos(rad);
var dirx = (Math.random() var步驟= 1;
var 間隔;
this.SetLocation = function (vx, vy) { x = vx; y = vy; }
this.SetDirection = function (vx, vy) { dirx = vxx ;迪里= vy; }
obj.CustomMethod = function () {
obj.style.left = (x AdMoveConfig.ScrollX) "px";
obj.style.top = (y AdMoveConfig. ScrollY) "px";
rad = (Math.random() 1) * Math.PI / 6;
W = AdMoveConfig.MoveWidth - obj.offsetWidth;
H = AdMoveConfig.MoveHeight - obj. offsetHeight;
x = x 步驟* kx * dirx;
if (x if (x > W) { dirx = -1; x = W; kx = Math.sin(rad); ky = Math.cos(rad); }
y = y 步驟* ky * diry ;
if (y if (y > H) { diry = -1; y=H; kx = Math.sin(rad); ky = Math.cos(rad); }
}
this.Run = function () {
var 延遲= 10;
interval = setInterval(obj.CustomMethod, 延遲);
obj.onmouseover = function () {clearInterval(interval); }
obj.onmouseout = function () { 間隔= setInterval(>obj.onmouseout = function () { 間隔= setInterval(obj.Custom, Methodobj.Custom, Method ); }
}
}






相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
最新問題
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板