jquery - js向兩邊展開
問題描述
比如我有這樣一個p寬100高100我想點擊的是時候讓他的展示方式是從中間向兩邊展開,css3要怎么寫
問題解答
回答1:<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Document</title> <style>.outter { position: relative; width: 202px; height: 400px;}.left,.right { position: absolute; top: 0; left: 0; display: inline-block; width: 100px; height: 400px; background-color: #000;}.right { left: inherit; right: 0;}.ani { animation: ani 5s; -moz-animation: ani 5s; /* Firefox */ -webkit-animation: ani 5s; /* Safari 和 Chrome */ -o-animation: ani 5s;}@keyframes ani { from {width: 100px; } to {width: 0; }} </style></head><body> <p class='outter'><p class='left inner'></p><p class='right inner'></p> </p> <script src='http://cdn.bootcss.com/jquery/2.2.1/jquery.js'></script> <script>$(function() { var inner = $(’.inner’); $(’.outter’).one(’click’, function() {inner.addClass(’ani’).on(’webkitAnimationEnd’, function() { inner.hide();}); }); }); </script></body></html>回答2:
作為初學者,看樓主提問帶的標簽里有JQ,就興致勃勃地寫了一下。其實樓上的CSS3屬性真心很好啊!
<!DOCTYPE html><html><head> <meta charset='utf-8'> <meta http-equiv='X-UA-Compatible' content='IE=edge'> <title>兩邊展開</title> <link rel='stylesheet' href='http://www.aoyou183.cn/wenda/5947.html'> <style> .content {width: 100px;height: 100px;position: relative;overflow: hidden; }.content p {position: absolute;width: 49px;height: 100px; }.left {left: 0;background-color: black;margin-right: 2px; }.right {background-color: black;right: 0; } </style></head><body> <p class='content'><p class='left'></p><p class='right'></p> </p> <script src='http://www.aoyou183.cn/wenda/js/jquery-1.12.0.min.js'></script> <script> $(function() {$('.content').click(function() { $('.left').animate({left: '-49px' }, 1000); $('.right').animate({right: '-49px' }, 1000)}) }) </script></body></html>回答3:
使用translateX(n)屬性,文檔看下面http://www.w3school.com.cn/css3/css3_2dtransform.asp
相關文章:
1. mysql數據庫做關聯一般用id還是用戶名2. linux運維 - python遠程控制windows如何實現3. thinkPHP5中獲取數據庫數據后默認選中下拉框的值,傳遞到后臺消失不見。有圖有代碼,希望有人幫忙4. python小白 關于類里面的方法獲取變量失敗的問題5. python - 如何對列表中的列表進行頻率統計?6. javascript - 如何用最快的速度C#或Python開發一個桌面應用程序來訪問我的網站?7. Python2中code.co_kwonlyargcount的等效寫法8. django - Python error: [Errno 99] Cannot assign requested address9. python小白,關于函數問題10. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?
