**前言:**由於忽然想研究研究側邊欄滑動展開收起怎麼作的,就去baidu了一下transition。css
先來看一下個人代碼:html
<div class="detail"> <div class="div1">詳情</div> <div class="div2"> <div>內容1</div> <div>內容1</div> <div>內容1</div> <div>內容1</div> <div>內容1</div> </div> </div> <style> .detail { position: fixed; right: -100px; transition: right 1s; } .detail:hover { right: 0; } .div1 { background-color: green; border-top-left-radius: 10%; border-bottom-left-radius: 10%; width: 50px; height: 30px; float: left; } .div2 { background-color: green; width: 100px; height: 100px; float: left; }
我先把整個div都移到屏幕外面,只留下詳情顯示出來,當鼠標懸浮到詳情上的時候,把righ變成0,就能夠從右邊出來了,固然直接出來確定很差看,就加了一個過渡動畫transition,使其緩慢的滑動出來佈局
具體怎麼用transition看這個:https://www.cnblogs.com/zouwangblog/articles/11022116.html動畫
解決安卓滑動卡頓
安卓滑動會卡頓主要是由於transition渲染margin,left,right,top,bottom的時候會計算不少值,具體計算了什麼能夠去baidu一下,這裏就講解決辦法。spa
當transition計算margin,left,right,top,bottom類的值時會卡頓,把方向移動換成transform,再放在transition中就能夠解決卡頓。code
/**這是控制左右移動*/ .rule { transform: translateX(80vw); transition: transform 1s; } .rule2 { transform: translateX(2vw); transition: transform 1s; } /**如下是內容佈局*/ .rule-title { background-color: #F4A627; border-top-left-radius: 25px; border-bottom-left-radius: 25px; text-align: center; line-height: 30px; width: 20vw; height: 30px; float: left; } .rule-detail { padding: 0 6px; background-color: #F4A627; width: 75vw; height: 100%; float: left; line-height: 30px; border-bottom-left-radius: 5px; }