底部播放器插件

写了个播放器练手

position: relative; 元素移动后会造成占位

解决办法是

father  position: relative;   childs   position: absolute;


本来是想做成底部鼠标离开后2s自动隐藏,鼠标悬浮 播放器自动展开

事件触发是用onmouseout 和 onmouseover

但是发现会多次触发

测试代码如下

鼠标进入 child 后会先触发一个onmouseout  再触发 onmouseover

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
	<style type="text/css">
		#father{
			width: 100%;
			height: 100px;
			background-color: #2A58E7;
			display: flex;

		}

		.child{
			position: relative;
			margin: 0 auto;
			width: 20%;
			height: 100px;
			background-color: #F612CF;
		}
	</style>

	<script type="text/javascript">
		window.οnlοad=function(){

			document.getElementById("father").οnmοuseοver=function(){
				console.log("onmouseover");
			}
			document.getElementById("father").οnmοuseοut=function(){
				console.log("onmouseout");
			}

		}
		
	</script>
</head>
<body>
	<div id="father">
		<div class="child"></div>
	 </div>
	 
</body>
</html>

所以把以下写法改了一下

以下代码为改前

	document.getElementById("bottom_music").οnmοuseοut=function(e){
		
		if(hidden==0){
			silder_hide();
		}

	}
	document.getElementById("bottom_music").οnmοuseοver=function(e){
		
		if(hidden==1){
			silder_show();
		}
		
	}

	function silder_hide(){

		setTimeout(function(){
			document.getElementById("bottom_music").style.transform="translate(0px,50px)";
			hidden=1;
		},2000);	
		
	}

	function silder_show(){
		var oDom=document.getElementById("bottom_music").style.transform;
		//alert(oDom.length);
		if(oDom.length>0){
			document.getElementById("bottom_music").style.transform="";
			hidden=0;
		}
		
	}
以下代码为修改后 加了个变量判断

	document.getElementById("bottom_music").οnmοuseοut=function(e){
		hidden_in=1;
		if(hidden==0){
			silder_hide();
		}

	}
	document.getElementById("bottom_music").οnmοuseοver=function(e){
		hidden_in=0;
		if(hidden==1){
			silder_show();
		}
	}

	function silder_hide(){

		setTimeout(function(){
			if(hidden_in==1){
				document.getElementById("bottom_music").style.transform="translate(0px,50px)";
				hidden=1;		
			}
		},2000);	
		
	}

	function silder_show(){
		var oDom=document.getElementById("bottom_music").style.transform;
		//alert(oDom.length);
		if(oDom.length>0){
			document.getElementById("bottom_music").style.transform="";
			hidden=0;
		}
		
	}

虽然是简单的东西但还是要慢慢练习吧

项目地址 https://github.com/1036875207/music-bottom-bar

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值