同一个网页中俩个js特效对onmouseover 事件冲突 应该改怎么调试 谢谢各位师傅
function$(id){returndocument.getElementById(id);}functionaddLoadEvent(func){varoldonl...
function $(id) { return document.getElementById(id); }
function addLoadEvent(func){
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function (){
oldonload();
func();
}
}
}
function moveElement(elementID,final_x,final_y,interval) {
if (!document.getElementById) return false;
if (!document.getElementById(elementID)) return false;
var elem = document.getElementById(elementID);
if (elem.movement) {
clearTimeout(elem.movement);
}
if (!elem.style.left) {
elem.style.left = "0px";
}
if (!elem.style.top) {
elem.style.top = "0px";
}
var xpos = parseInt(elem.style.left);
var ypos = parseInt(elem.style.top);
if (xpos == final_x && ypos == final_y) {
return true;
}
if (xpos < final_x) {
var dist = Math.ceil((final_x - xpos)/10);
xpos = xpos + dist;
}
if (xpos > final_x) {
var dist = Math.ceil((xpos - final_x)/10);
xpos = xpos - dist;
}
if (ypos < final_y) {
var dist = Math.ceil((final_y - ypos)/10);
ypos = ypos + dist;
}
if (ypos > final_y) {
var dist = Math.ceil((ypos - final_y)/10);
ypos = ypos - dist;
}
elem.style.left = xpos + "px";
elem.style.top = ypos + "px";
var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
elem.movement = setTimeout(repeat,interval);
}
function classNormal(iFocusBtnID,iFocusTxID){
var iFocusBtns= $(iFocusBtnID).getElementsByTagName('li');
var iFocusTxs = $(iFocusTxID).getElementsByTagName('li');
for(var i=0; i<iFocusBtns.length; i++) {
iFocusBtns[i].className='normal';
代码2
window.onload = function gun()
{
var oBox = document.getElementById("box");
var aUl = document.getElementsByTagName("dl");
var aImg = aUl[0].getElementsByTagName("dt");
var aNum = aUl[1].getElementsByTagName("dt");
var timer = play = null;
var i = index = 0;
//切换按钮
for (i = 0; i < aNum.length; i++)
{
aNum[i].index = i;
aNum[i].onmouseover = function gun()
{
show(this.index)
}
}
//鼠标划过关闭定时器
oBox.onmouseover = function gun()
{
clearInterval(play)
};
//鼠标离开启动自动播放
oBox.onmouseout = function gun()
{
autoPlay()
};
//自动播放函数
function autoPlay ()
{
play = setInterval(function gun() {
index++;
index >= aImg.length && (index = 0);
show(index);
},5000);
}
autoPlay();//应用
//图片切换, 淡入淡出效果
function show (a)
{
index = a;
var alpha = 0;
for (i = 0; i < aNum.length; i++)aNum[i].className = "";
aNum[index].className = "sp-currentt";
clearInterval(timer);
for (i = 0; i < aImg.length; i++)
{
aImg[i].style.opacity = 0;
aImg[i].style.filter = "alpha(opacity=0)";
}
timer = setInterval(function gun() {
alpha += 2;
alpha > 100 && (alpha =100);
aImg[index].style.opacity = alpha / 100;
aImg[index].style.filter = "alpha(opacity = " + alpha + ")";
alpha == 100 && clearInterval(timer)
},20);
}
};
</script> 展开
function addLoadEvent(func){
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function (){
oldonload();
func();
}
}
}
function moveElement(elementID,final_x,final_y,interval) {
if (!document.getElementById) return false;
if (!document.getElementById(elementID)) return false;
var elem = document.getElementById(elementID);
if (elem.movement) {
clearTimeout(elem.movement);
}
if (!elem.style.left) {
elem.style.left = "0px";
}
if (!elem.style.top) {
elem.style.top = "0px";
}
var xpos = parseInt(elem.style.left);
var ypos = parseInt(elem.style.top);
if (xpos == final_x && ypos == final_y) {
return true;
}
if (xpos < final_x) {
var dist = Math.ceil((final_x - xpos)/10);
xpos = xpos + dist;
}
if (xpos > final_x) {
var dist = Math.ceil((xpos - final_x)/10);
xpos = xpos - dist;
}
if (ypos < final_y) {
var dist = Math.ceil((final_y - ypos)/10);
ypos = ypos + dist;
}
if (ypos > final_y) {
var dist = Math.ceil((ypos - final_y)/10);
ypos = ypos - dist;
}
elem.style.left = xpos + "px";
elem.style.top = ypos + "px";
var repeat = "moveElement('"+elementID+"',"+final_x+","+final_y+","+interval+")";
elem.movement = setTimeout(repeat,interval);
}
function classNormal(iFocusBtnID,iFocusTxID){
var iFocusBtns= $(iFocusBtnID).getElementsByTagName('li');
var iFocusTxs = $(iFocusTxID).getElementsByTagName('li');
for(var i=0; i<iFocusBtns.length; i++) {
iFocusBtns[i].className='normal';
代码2
window.onload = function gun()
{
var oBox = document.getElementById("box");
var aUl = document.getElementsByTagName("dl");
var aImg = aUl[0].getElementsByTagName("dt");
var aNum = aUl[1].getElementsByTagName("dt");
var timer = play = null;
var i = index = 0;
//切换按钮
for (i = 0; i < aNum.length; i++)
{
aNum[i].index = i;
aNum[i].onmouseover = function gun()
{
show(this.index)
}
}
//鼠标划过关闭定时器
oBox.onmouseover = function gun()
{
clearInterval(play)
};
//鼠标离开启动自动播放
oBox.onmouseout = function gun()
{
autoPlay()
};
//自动播放函数
function autoPlay ()
{
play = setInterval(function gun() {
index++;
index >= aImg.length && (index = 0);
show(index);
},5000);
}
autoPlay();//应用
//图片切换, 淡入淡出效果
function show (a)
{
index = a;
var alpha = 0;
for (i = 0; i < aNum.length; i++)aNum[i].className = "";
aNum[index].className = "sp-currentt";
clearInterval(timer);
for (i = 0; i < aImg.length; i++)
{
aImg[i].style.opacity = 0;
aImg[i].style.filter = "alpha(opacity=0)";
}
timer = setInterval(function gun() {
alpha += 2;
alpha > 100 && (alpha =100);
aImg[index].style.opacity = alpha / 100;
aImg[index].style.filter = "alpha(opacity = " + alpha + ")";
alpha == 100 && clearInterval(timer)
},20);
}
};
</script> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询