为了账号安全,请及时绑定邮箱和手机立即绑定

请问这BUG是什么情况?

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<style type="text/css">
			* {
				margin: 0;
				padding: 0;
			}
			
			.lis {
				height: 60px;
				width: 260px;
				background-color: antiquewhite;
				border-radius: 60px;
				margin-top: 10px;
				line-height: 60px;
				text-align: center;
				border: 5px solid cadetblue;
				opacity: 0.5;
				box-shadow: 5px 2px 10px darkred;
			}
		</style>
	
		<script type="text/javascript">
			function getclsname(clsname, parent) {
				var oparent = parent ? document.getElementById(parent) : document,
					eles = [],
					elements = oparent.getElementsByTagName("*");
				for (var i = 0, l = elements.length; i < l; i++) {
					if (elements[i].className == clsname) {
						eles.push(elements[i]);
					}
				}
				return eles;
			}
/*			function getstyle(obj,sty){
				if(obj.currentStyle){
					return obj.currentStyle[sty];
				}else{
					return getComputedStyle(obj,null)[sty];
				}
			}*/
			
			window.onload = function() {
				var lis = getclsname("lis", "oul"),
					btn=document.getElementById("bt"),
					txt=document.getElementById("text"),
					speed = 10,
					sty = null;
				btn.onclick=function(){
					sty=txt.value;
					document.title=sty;
				}
				for (var i = 0, l = lis.length; i < l; i++) {
					this.timer=null;
					lis[i].onmouseover = function() {
						lis_over(this, speed, 0, 500,1,sty);
					}
					lis[i].onmouseleave = function() {
						lis_over(this, speed, 1, 260,0.5,sty);
					}
				}
			}

			function lis_over(obj, speed, lg, itg,op,sty) {
				clearInterval(obj.timer);
				obj.timer = setInterval(function() {
					var wd=window.getComputedStyle(obj,null)[sty];
					if(sty=='opacity'){
						wd=Math.round(parseFloat(wd)*100);
					}else{
						wd=parseInt(wd);
					}
					if (wd == itg||wd/100==op) {
						clearInterval(obj.timer);
					} else {
						if(lg!=0){
							speed=-10;
						}
						if(sty=='opacity'){
							var a = wd + speed;
							if(a<0||a==0){
								obj.style[sty] = op;
								clearInterval(obj.timer);
							}else{
								obj.style[sty] = a/100;
							}
						}else{
							if(wd>itg&&lg!=0){
								obj.style[sty]=itg+"px";
								clearInterval(obj.timer);
							}else if(wd<itg&&lg==0){
								obj.style[sty]=itg+"px";
								clearInterval(obj.timer);
							}
							if(wd>800/2){
								if(lg==0){speed=sp+10;}
								else{speed=-sp-10;}
							}
							obj.style[sty] = wd + speed + "px";
						}
					}

				}, 100)
			}

		</script>
	</head>

	<body>
		<div>
			<input type="text" id="text" style="color:grey" value="opacity" onfocus="this.value=''"/>
			<input type="button" id="bt" value="确定" />
		</div>
		<ul id=oul>
			<li class="lis">imooc</li>
			<li class="lis"></li>
			<li class="lis"></li>
			<li class="lis"></li>
			<li class="lis"></li>
			<li class="lis"></li>
		</ul>
	</body>

</html>

输入“width",点击确定,width值只会增长一次,然后就被clearinterval了,明明是&&,怎么还是直接执行了?非常感谢!

正在回答

5 回答

width的第一次 onmouseover触发参数为 wd=260,itg=500,lg=0,满足 else if(wd<itg&&lg==0) 这个条件,自然就被你clear掉了

0 回复 有任何疑惑可以回复我~
#1

飞天意大利面神兽 提问者

非常感谢!
2016-07-04 回复 有任何疑惑可以回复我~

前端设计。。。

http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=20653http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=20912http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=20275http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=20196http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=20925http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=21468http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=21327http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=20670http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=20625http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=21136http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=21025http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=20227http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=21477http://www.yuli.gov.cn/QA/ShowQuestion.aspx?Id=20364https://wap.zol.com.cn/index.php?c=List_List&keyword=%E7%BC%85%E7%94%B8%E9%91%AB%E4%BD%B0%E5%88%A9%E5%A8%B1%E4%B9%90%E8%AF%A6%E7%BB%86%E5%9C%B0%E5%9D%80%E3%80%90%E5%AE%98%E7%BD%91%E2%86%92B2024%C2%B7CN%E3%80%91%E5%B8%B8%E5%BE%B7%E5%8A%9E%E4%BA%8B%E5%A4%84http://iias.tsinghua.edu.cn/search/%E8%BF%AA%E5%A8%81%E5%9B%BD%E9%99%85%E7%BB%8F%E7%BA%AA%E4%BA%BA%E8%81%94%E7%B3%BB%E5%BC%80%E6%88%B7%E5%BE%AE%E4%BF%A1%E5%BC%80%E6%88%B7%E7%94%B5%E8%AF%9D%E3%80%90B2024.CN%E6%AC%A2%E8%BF%8E%E6%82%A8%E3%80%91%E5%95%86%E6%B4%9B%E8%81%94%E9%80%9Ahttps://www.fastsoso.cc/search?k=%E7%9A%87%E5%AE%B6%E5%9B%BD%E9%99%85%E5%9C%A8%E7%BA%BF%E5%85%AC%E5%8F%B8%E8%BF%94%E7%82%B9%E7%BD%91%E5%9D%80TL262.%EF%BC%A3%EF%BC%AF%EF%BC%AD%E6%9C%AC%E6%BA%AA%E9%AB%98%E6%A0%A1%EF%BC%BD%EF%BC%9A%EF%BD%95https://wap.zol.com.cn/index.php?c=List_List&keyword=%E7%BC%85%E7%94%B8%E9%BE%99%E6%BA%90%E8%B5%8C%E5%9C%BA%E6%AD%A3%E8%A7%84%E5%90%97%E7%9B%B4%E8%90%A5%E5%BC%80%E6%88%B7%3AB2024%C2%B7CN%E5%AE%9D%E9%B8%A1%E7%BD%91%E7%BA%A2%EF%BD%93https://search.bilibili.com/all?keyword=%E8%80%81%E8%A1%97%E6%96%B0%E7%99%BE%E8%83%9Capp%E3%80%90%E5%AE%98%E7%BD%91%E2%86%92TL262%C2%B7%EF%BC%A3%EF%BC%AF%EF%BC%AD%E3%80%91%E5%B8%B8%E5%B7%9E%E8%8A%82%E7%9B%AE%E8%A1%A8https://minecraft.fandom.com/zh/wiki/UserProfile:%E6%96%B0%E4%B8%96%E7%95%8C%E5%AE%98%E6%96%B9%E7%9B%B4%E8%90%A5%E7%BD%91B2024.CN%E5%95%86%E6%B4%9B%E8%81%94%E9%80%9A%EF%BC%B9%EF%BD%91%EF%BC%A8?variant=zh-hk&cb=&mobileaction=toggle_view_mobilehttps://wap.zol.com.cn/index.php?c=List_List&keyword=%E9%91%AB%E7%99%BE%E5%88%A9%E5%9C%A8%E7%BA%BF%E7%BD%91%E6%8A%95%E7%94%B5%E8%AF%9D%E3%80%90B2024%C2%B7CN%E3%80%91%E9%98%9C%E6%96%B0%E8%AE%BF%E8%B0%88

0 回复 有任何疑惑可以回复我~

致谢!

0 回复 有任何疑惑可以回复我~

else if(wd<itg&&lg==0){

                                obj.style[sty]=itg+"px";

                                clearInterval(obj.timer);

                            }

中的clearInterval(obj.timer);删掉就行了

1 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

请问这BUG是什么情况?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信