亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

為什么設置了clearInterval()沒有效果了。

為什么設置了clearInterval()沒有效果了。

<!DOCTYPE?html>
<html?lang="en/zh">
<head>
????<meta?charset="UTF-8">
????<title>JS動畫</title>????
????<style?type="text/css">
????????*{
????????????padding:?0px;
????????????margin:?0px;
????????}
????????#share{
????????????width:?200px;
????????????height:?200px;????????????
????????????background:?#2dcb7c;
????????????position:?relative;????????????
????????????left:-200px;
????????}
????????#share?span{
????????????width:?60px;
????????????height:?50px;
????????????line-height:?50px;
????????????background:?#272822;
????????????position:?absolute;/*發現了一個秘密,只要用了定位,就可以把inline元素轉換層block元素*/
????????????right:?-60px;
????????????top:?75px;
????????????text-align:?center;
????????}
????</style>????
</head>
<body>
????<div?id="share">
????????<span>分享</span>
????</div>


<!--?javascript代碼?-->
????<script?type="text/javascript">????????
????????????window.onload?=function(){????
?????????????????var?odiv=document.getElementById("share");????????????
????????????????odiv.onmouseover=function(){
????????????????????gos();
????????????????}
????????????}
????????????/*動畫函數*/
????????????var?timer=null;
????????????function?gos(){
????????????????clearInterval(timer);
????????????????var?odiv=document.getElementById("share");????????????????????????????????????????
????????????????????timer=setInterval(function(){
????????????????????if(odiv.offsetLeft?==-10){
????????????????????????clearInterval(timer);
????????????????????}
????????????????????odiv.style.left=odiv.offsetLeft+10+"px";
????????????????},30)????????
????????????}????????
????</script>????????
</body>
</html>


正在回答

1 回答

<!DOCTYPE html>

<html lang="en/zh">

<head>

? ? <meta charset="UTF-8">

? ? <title>JS動畫</title> ? ?

? ? <style type="text/css">

? ? ? ? *{

? ? ? ? ? ? padding: 0px;

? ? ? ? ? ? margin: 0px;

? ? ? ? }

? ? ? ? #share{

? ? ? ? ? ? width: 200px;

? ? ? ? ? ? height: 200px; ? ? ? ? ? ?

? ? ? ? ? ? background: #2dcb7c;

? ? ? ? ? ? position: relative; ? ? ? ? ? ?

? ? ? ? ? ? left:-200px;

? ? ? ? }

? ? ? ? #share span{

? ? ? ? ? ? width: 60px;

? ? ? ? ? ? height: 50px;

? ? ? ? ? ? line-height: 50px;

? ? ? ? ? ? background: #272822;

? ? ? ? ? ? position: absolute;/*發現了一個秘密,只要用了定位,就可以把inline元素轉換層block元素*/

? ? ? ? ? ? right: -60px;

? ? ? ? ? ? top: 75px;

? ? ? ? ? ? text-align: center;

? ? ? ? }

? ? </style> ? ?

</head>

<body>

? ? <div id="share">

? ? ? ? <span>分享</span>

? ? </div>

?

?

<!-- javascript代碼 -->

? ? <script type="text/javascript"> ? ? ? ?

? ? ? ? ? ? window.onload =function(){ ? ?

? ? ? ? ? ? ? ? ?var odiv=document.getElementById("share"); ? ? ? ? ? ?

? ? ? ? ? ? ? ? odiv.onmouseover=function(){

? ? ? ? ? ? ? ? ? ? gos();

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? ? ? /*動畫函數*/

? ? ? ? ? ? var timer=null;

? ? ? ? ? ? function gos(){

? ? ? ? ? ? ? ? clearInterval(timer);

? ? ? ? ? ? ? ? var odiv=document.getElementById("share"); ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?

? ? ? ? ? ? ? ? ? ? timer=setInterval(function(){

? ? ? ? ? ? ? ? ? ? if(odiv.offsetLeft >=-10){

? ? ? ? ? ? ? ? ? ? ? ? clearInterval(timer);

? ? ? ? ? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? ? ? odiv.style.left=odiv.offsetLeft+10+"px";}

? ? ? ? ? ? ? ? },30) ? ? ? ?

? ? ? ? ? ? } ? ? ? ?

? ? </script> ? ? ? ?

</body>

</html>


改了一下

3 回復 有任何疑惑可以回復我~
#1

記得喝水 提問者

非常感謝!
2015-12-06 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
JS動畫效果
  • 參與學習       113918    人
  • 解答問題       1502    個

通過本課程JS動畫的學習,從簡單動畫開始,逐步深入各種動畫框架封裝

進入課程

為什么設置了clearInterval()沒有效果了。

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號