css position fixed 在移动端上为什么会 晃来晃去

html-css07

css position fixed 在移动端上为什么会 晃来晃去,第1张

在自己手机上打开页面,向下滑动时这个div会出现短暂的向下瞬间移动之后马上跳回到最顶部,网上资料表明是position:fixed不兼容某些浏览器的缘故,解决方法有多种:

1.给这个设置了position:fixed的元素再设置一个CSS属性:-webkit-transform: translateZ(0)

2.给html, body元素设置CSS属性 {height:100%overflow:automargin: 0}

3.引入jquery1.7.2的类库,<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>

4.在fiexd内设置position:absolute,如:

<div style="position:fiexdbottom:0px">

<div style="position:absolute">

</div>

</div>

望采纳!

<!DOCTYPE html>

<html>

<head> 

<meta charset="utf-8"> 

<title></title> 

<style>

*{ padding:0margin:0font-size:14px }

body{

background: grey

}

.d{

position:fixedmargin:autoleft:0right:0bottom:24pxwidth: 160pxheight:120px

animation: d1 3s linear animation-fill-mode: both

}

@keyframes d1{

from{

bottom: 24px

}

to{

bottom: 360px

}

}

.d img{

height:120pxposition: absolutemargin:autoleft:0top:0animation: d2 2s 3s linear infinite animation-fill-mode: both

}

@keyframes d2{

0%,100%{

transform:rotate(0deg)

}

50%{  

left: 40px

transform:rotate(90deg)

}

}

</style>

</head>

<body>

<div class="d">

<img src="http://aimusic.image.alimmdn.com/Image/6d235b11f15838d6711ec6b0ca5e1a32.png"/>

</div>

</body>

</html>