Jump to content
  • 0

Как остановить функцию?


Destrifer
 Share

Question

Нужно чтобы при убирании мышки с div-ов, функции my2() (или my3()) прекратили выполняться. Насчет обработчика ясно, а что прописать в него?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
b=250;
function my2()
{
if(b==115) {return};
setTimeout('my2()',10);
b -= 1;
document.getElementById("div1").style.top = b + 'px';
document.getElementById('tt').innerHTML = b;
}
function my3()
{
if(b==250) {return};
setTimeout('my3()',10);
b += 1;
document.getElementById("div1").style.top = b + 'px';
document.getElementById('tt').innerHTML = b;
}

</script>
<style>
#div1 {
width: 164px;
position: fixed;
background-color:#000099;
z-index: 1;
}
.div11 {
width: 164px;
position: absolute;
height:136px;
top: 30%;
background-color:#009900;
z-index: 0;
}
.div111 {
width: 164px;
height:136px;
position: absolute;
top: 30%;
background-color:#990000;
z-index: 1;
clip: rect(0 164px 136px 0);
}
#div1 > a {
display: block;
text-decoration: none;
color: #ffffff;
padding: 5px;
background:#212121;
border: 2px ridge #000;
}
#div1 > a:hover {background: #7f7f7f;}
.div3 {
position:absolute;
top:0;
left:50%;
margin-left:-41px;
margin-top:-26px;
}
.div3 a {
text-decoration: none;
color: #ffffff;
border: 2px ridge #000;
background:#212121;
padding: 5px 30px;
}
.div3 a:hover {background: #7f7f7f;}
.div4 {
position:absolute;
left:50%;
top:100%;
margin-left:-41px;
margin-top:7px;
}
.div4 a {
text-decoration: none;
color: #ffffff;
border: 2px ridge #000;
background:#212121;
padding: 5px 30px;
}
.div4 a:hover {background: #7f7f7f;}
</style>
</head>

<body>
<div class="div111">
<div id="div1">
<a href="#" >111</a>
<a href="#" >222</a>
<a href="#" >333</a>
<a href="#" >444</a>
<a href="#" >555</a>
<a href="#" >666</a>
<a href="#" >777</a>
<a href="#" >888</a>
</div>
</div>
<div class="div11">
<div class="div3" onmouseover="my2();"><a href="#">←</a></div>
<div class="div4" onmouseover="my3();"><a href="#">←</a></div>
</div>
<div id='tt'></div>
</body>
</html>

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

var stp=false;
function my2()
{
if(b==115||stp) {return};
setTimeout('my2()',10);
b -= 1;
document.getElementById("div1").style.top = b + 'px';
document.getElementById('tt').innerHTML = b;
}
function my3()
{
if(b==250||stp) {return};
setTimeout('my3()',10);
b += 1;
document.getElementById("div1").style.top = b + 'px';
document.getElementById('tt').innerHTML = b;
}

В обработчике делаем stp=true;

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. See more about our Guidelines and Privacy Policy