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='https://www.haobala.com/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='https://www.haobala.com/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优化 - mysql count(id)查询速度如何优化?2. python - django 里自定义的 login 方法,如何使用 login_required()3. javascript - git clone 下来的项目 想在本地运行 npm run install 报错4. node.js - node_moduls太多了5. mysql主从 - 请教下mysql 主动-被动模式的双主配置 和 主从配置在应用上有什么区别?6. angular.js - 不适用其他构建工具,怎么搭建angular1项目7. 主从备份 - 跪求mysql 高可用主从方案8. android-studio - Android 动态壁纸LayoutParams问题9. python如何不改动文件的情况下修改文件的 修改日期10. 在Java中System.out.println 只能在method中使用吗?
