jquery - css3 scale 縮放圖片問題
問題描述
我想點擊document讓p的圖片從中心點向兩邊展開一張圖片的大小用了css3的縮放,但是他會把圖片弄失真,問下用css3能否實現
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Document</title> <style>p { width:1px; background:url(http://www.ppt123.net/beijing/UploadFiles_8374/201203/2012032518062306.jpg); background-size:cover; height:600px; margin:100px auto; -webkit-transform-origin:left top; -moz-transform-origin:left top; -o-transform-origin:left top; -ms-transform-origin:left top; transform-origin:left top; -webkit-transition:1s; -moz-transition:1s; -o-transition:1s;} </style></head><body> <p class='outter'></p> <script src='http://cdn.bootcss.com/jquery/2.2.1/jquery.js'></script> <script>$(function() { $(document).on(’click’,function(){ $(’p’).css({ ’-webkit-transform’:’scaleX(800)’,’transform’:’scaleX(800)’ }) })}); </script></body></html>
問題解答
回答1:方法一:js<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Document</title> <style>p { width:0; height:0;position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); transform-origin: 50% 50%;background:url(http://www.ppt123.net/beijing/UploadFiles_8374/201203/2012032518062306.jpg); background-size:cover;} </style></head><body> <p class='outter'></p> <script src='http://cdn.bootcss.com/jquery/2.2.1/jquery.js'></script> <script>$(function() { $(document).on(’click’,function(){ $(’p’).stop(true).animate({ width: 800, height: 600 }) })}); </script></body></html>方法二:scale
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Document</title> <style>p { width: 800px; height: 600px; margin: 100px auto 0; transform: scale(0); transform-origin: 50% 50%; transition: transform .4s ease-in-out; background:url(http://www.ppt123.net/beijing/UploadFiles_8374/201203/2012032518062306.jpg); background-size:cover;} </style></head><body> <p class='outter'></p> <script src='http://cdn.bootcss.com/jquery/2.2.1/jquery.js'></script> <script>$(function() { $(document).on(’click’,function(){ $(’p’).css({ 'transform': 'scale(1)' }) })}); </script></body></html>方法三:純CSS
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <title>Document</title> <style>.outter { width: 800px; height: 600px; margin: 100px auto 0; background-color: gray;}.inner { width: 800px; height: 600px; transform: scale(0); transform-origin: 50% 50%; transition: transform .4s ease-in-out; background:url(http://www.ppt123.net/beijing/UploadFiles_8374/201203/2012032518062306.jpg); background-size:cover;}.outter:hover .inner { transform: scale(1);} </style></head><body> <p class='outter'><p class='inner'></p> </p></body></html>回答2:
你的圖片是位圖,放大肯定會失真,你要用矢量圖。你用css3也可以實現,要用高版本的瀏覽器。但是圖片照樣會失真。
回答3:你只放大x肯定失真。。模糊的話需要用矢量的
相關文章:
1. javascript - vue2.0中使用vue2-dropzone的demo,vue2-dropzone的github網址是什么??百度不到。2. vue計算屬性怎么樣與for結合使用3. angular.js - vue/react 渲染內容抖動4. javascript - html中這兩種方式為什么都不能讓<p>標簽居中?5. html5 - chrome下的a標簽download屬性無法調出另存為的下載框6. javascript - js let 和 var問題7. centos - rpm更新軟件wkhtmltox報錯8. javascript - 如何用最快的速度C#或Python開發一個桌面應用程序來訪問我的網站?9. html5 - chrome上的video控制條不同10. python - 為什么正常輸出中文沒有亂碼,zip函數之后出現中文編程unicode編碼的問題,我是遍歷輸出的啊。
