HTML5----CSS3圖片濾鏡(filter)特效

來源:互聯網
上載者:User

標籤:ima   eve   webkit   container   jsb   attr   art   ras   code   

支援Chrome:

暫不支援瀏覽器:FF,IE...

希望後者努力




CSS:

<style type="text/css">@-webkit-keyframes testAnim {0% {-webkit-filter: grayscale(0.5) blur(1px) saturate(2);}100% {-webkit-filter: grayscale(0.2) blur(6px) saturate(9);}}/*IE,FF暫不支援*/@-moz-keyframes testAnim {0% {-moz-filter: grayscale(0.5) blur(1px) saturate(2);}100% {-moz-filter: grayscale(0.2) blur(6px) saturate(9);}}@-ms-keyframes testAnim {0% {-ms-filter: grayscale(0.5) blur(1px) saturate(2);}100% {-ms-filter: grayscale(0.2) blur(6px) saturate(9);}}@keyframes testAnim {0% {filter: grayscale(0.5) blur(1px) saturate(2);}100% {filter: grayscale(0.2) blur(6px) saturate(9);}}#animatePhoto {}.animatePhoto:hover,#animatePhoto:hover{ -webkit-animation-name: testAnim; -webkit-animation-duration: 2s; -webkit-animation-iteration-count: 1; -webkit-animation-direction: alternate; -webkit-animation-timing-function: ease-out; -webkit-animation-fill-mode: forwards; -webkit-animation-delay: 0s;/*IE,FF暫不支援*/ -moz-animation-name: testAnim; -moz-animation-duration: 2s; -moz-animation-iteration-count: 1; -moz-animation-direction: alternate; -moz-animation-timing-function: ease-out; -moz-animation-fill-mode: forwards; -moz-animation-delay: 0s; -ms-animation-name: testAnim; -ms-animation-duration: 2s; -ms-animation-iteration-count: 1; -ms-animation-direction: alternate; -ms-animation-timing-function: ease-out; -ms-animation-fill-mode: forwards; -ms-animation-delay: 0s; animation-name: testAnim; animation-duration: 2s; animation-iteration-count: 1; animation-direction: alternate; animation-timing-function: ease-out; animation-fill-mode: forwards; animation-delay: 0s;}.l,.r{ width:40%; float:left; padding:40px;}</style>


HTML:

<div class="l">    <h3>圖片濾鏡特效實驗</h3>    <img id="fxPhoto" src="http://avatar.csdn.net/A/7/9/1_damys.jpg" />    <div id="sliderContainer"></div></div><div class="r">    <h3>圖片濾鏡特效實驗:hover</h3>    <img id="animatePhoto" class="animatePhoto" src="http://avatar.csdn.net/A/7/9/1_damys.jpg" /></div>



JS:拖動效果

<script type="text/javascript">var photo = jQuery("#fxPhoto");var filters = [{ name: "grayscale", cname: "黑白照片(灰階級)效果", def: "0", unit: "", min:0 , max:1.0, step: "0.01" },{ name: "blur", cname: "模糊效果", def: "0", unit: "px", min: 0, max: 10 , step: "1"},{ name: "sepia", cname: "老照片(褐黃色)效果", def: "0", unit: "", min: 0, max: 1.0 , step: "0.01"},{ name: "saturate", cname: "飽和度調整", def: "1", unit: "", min: 0, max: 1.0 , step: "0.01"},{ name: "opacity", cname: "透明度調整", def: "1", unit: "", min: 0, max: 1.0 , step: "0.01"},{ name: "brightness", cname: "亮度調整", def: "1", unit: "", min: 0, max: 1.0 , step: "0.01"},{ name: "contrast", cname: "對照度調整", def: "1", unit: "", min: 0, max: 1 , step: "0.01"},{ name: "hue-rotate", cname: "色調調整", def: "0", unit: "deg", min: 0, max: 360 , step: "1"},{ name: "invert", cname: "色彩反相", def: "0", unit: "", min: 0, max: 1.0 , step: "0.01"}];// Change eventfunction onChange() {var cssString = "";jQuery.each(filters, function() {var value = jQuery(‘#‘+this.name).val();// Update the value titlejQuery(‘#title_‘+this.name).html("<h3>" + this.cname + "(" + this.name + ":" +value + this.unit + ")</h3>");// Update CSS stringcssString += " " + this.name + "(" + value + this.unit + ")";});photo.attr(‘style‘, "-webkit-filter: " + cssString);}// For every filtervar container = jQuery("#sliderContainer");jQuery.each(filters, function() {container.append("<p id=‘title_"+this.name+"‘>"+this.cname+"</p>");container.append("<input onChange=‘onChange()‘ value=‘"+this.def+"‘ type=‘range‘ id=‘"+this.name+"‘ min=‘"+this.min+"‘ max=‘"+this.max+"‘ step=‘"+this.step+"‘>");});onChange();</script>


HTML5----CSS3圖片濾鏡(filter)特效

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.