jquery - css3 scale 縮放圖片問(wèn)題
問(wèn)題描述
我想點(diǎn)擊document讓p的圖片從中心點(diǎn)向兩邊展開(kāi)一張圖片的大小用了css3的縮放,但是他會(huì)把圖片弄失真,問(wèn)下用css3能否實(shí)現(xiàn)
<!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>
問(wèn)題解答
回答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:
你的圖片是位圖,放大肯定會(huì)失真,你要用矢量圖。你用css3也可以實(shí)現(xiàn),要用高版本的瀏覽器。但是圖片照樣會(huì)失真。
回答3:你只放大x肯定失真。。模糊的話需要用矢量的
相關(guān)文章:
1. vue2.0+webpack 如何使用bootstrap?2. PHP類封裝的插入數(shù)據(jù),總是插入不成功,返回false;3. javascript - 如圖,百度首頁(yè),查看源代碼為什么什么都沒(méi)有?4. mac連接阿里云docker集群,已經(jīng)卡了2天了,求問(wèn)?5. html5 - 如何禁用360極速瀏覽器的 瀏覽器內(nèi)核選擇6. vue 子組件watch監(jiān)聽(tīng)不到prop的解決7. 我畢業(yè)以后在工作之余學(xué)了 PHP,都是自學(xué) 現(xiàn)在在找這方面的工作 求前輩指導(dǎo)學(xué)習(xí)方向 工作常用的知識(shí)8. node.js - 如何重定向到public下的靜態(tài)html文件9. javascript - 關(guān)于jquery的ajax post數(shù)據(jù)的問(wèn)題10. mysql - 微信小程序如何提高查詢速度?
