Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

红绿灯变换(定时器应用) #7

Open
zlluGitHub opened this issue Apr 11, 2018 · 0 comments
Open

红绿灯变换(定时器应用) #7

zlluGitHub opened this issue Apr 11, 2018 · 0 comments

Comments

@zlluGitHub
Copy link
Owner

  • 定时器应用:setInterval(function(){ }, time )
    <script>
    //鼠标经过颜色改变
    function show1() {
        var qw =document.getElementById("box1")
        qw.style.background = "wheat";
    }
    function back1() {
        var qw =document.getElementById("box1")
        qw.style.background = "pink";
    }

    //定时器红绿灯
    var n=setInterval(function(){
        var dom=document.getElementById('box2');
        var clr=dom.style.background;
        if(clr=='red'){
        	dom.style.background='green';
        }
        else{
          dom.style.background='red';
      }
    },500)
    //定时器红绿黄灯
    var n=setInterval(function(){
        qiehuan();
    },1500)
    var qiehuan=function(){
    	var dom=document.getElementById('box3');
    	var clr=dom.style.background;
    	dom.style.background='yellow';
    	setTimeout(function(){
    		if(clr=='red'){
    			dom.style.background='green';
    		}
    		else{
    			dom.style.background='red'
    		}
    	},500);
    }
    </script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant