HTML5 canvas生成图片马赛克效果特效源码

版权:原创 更新时间:1年以上
[该文章底部包含文件资源,可根据自己情况,决定是否下载资源使用,时间>金钱,如有需要,立即查看资源]

以下是 HTML5 canvas生成图片马赛克效果特效源码 的示例演示效果:

当前平台(PC电脑)
  • 平台:

部分效果截图:

HTML5 canvas生成图片马赛克效果特效源码

HTML代码(index.html):

<!doctype html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>HTML5 canvas生成图片马赛克效果</title>
	<link rel="stylesheet" type="text/css" href="css/default.css">
	<style type="text/css">
		.thumb{margin-left: 5em;}
		.thumb img{max-width: 400px;}
	</style>
	<!--[if IE]>
		<script src="http://libs.useso.com/js/html5shiv/3.7/html5shiv.min.js"></script>
	<![endif]-->
</head>
<body>
	<div class="container">
		<div class="content bgcolor-8">
			<h3 class="center">注意:文件下载到本地后在Chrome和IE浏览器中可能看不到效果<br>请使用Firefox浏览器在本地计算机查看该DEMO。</h3>
			<p class="center">Change pixel resolution <input type="range" min="4" max="100" value="32" id="range" /> <span id="output">32</span></p>
			<div class="thumb">
			    <img src="img/1.jpg" id="dolly1" />
			    <img src="img/2.jpg" id="dolly2" />
			    <img src="img/3.jpg" id="dolly3" />
			 </div>
		</div>
	</div>
	
	<script src="js/close-pixelate.js"></script>
	<script>
	window.onload = function() {
	  var dolly1 = document.getElementById('dolly1')
	  var dolly2 = document.getElementById('dolly2')
	  var dolly3 = document.getElementById('dolly3')
	  var pixelOpts = [ { resolution: 32 } ]
	  var pixelDolly1 = dolly1.closePixelate( pixelOpts )
	  var pixelDolly2 = dolly2.closePixelate( pixelOpts )
	  var pixelDolly3 = dolly3.closePixelate( pixelOpts )
	  var range = document.getElementById('range')
	  var output = document.getElementById('output')

	  range.addEventListener( 'change', function( event ) {
	    var res = parseInt( event.target.value, 10 )
	    res = Math.floor( res / 2 ) * 2
	    res = Math.max( 4, Math.min( 100, res ) )
	    output.textContent = res
	    // console.log( res );
	    pixelOpts = [ { resolution: res } ]
	    pixelDolly1.render( pixelOpts )
	    pixelDolly2.render( pixelOpts )
	    pixelDolly3.render( pixelOpts )
	  }, false )
	}
	</script>
</body>
</html>

CSS代码(default.css):

[class^="icon-"],[class*=" icon-"]{font-family:'icomoon';speak:none;font-style:normal;font-weight:normal;font-variant:normal;text-transform:none;line-height:1;/* Better Font Rendering =========== */
-webkit-font-smoothing:antialiased;-moz-osx-font-smoothing:grayscale;}
body,html{font-size:100%;padding:0;margin:0;}
/* Reset */
*,*:after,*:before{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;}
/* Clearfix hack by Nicolas Gallagher:http://nicolasgallagher.com/micro-clearfix-hack/ */
.clearfix:before,.clearfix:after{content:" ";display:table;}
.clearfix:after{clear:both;}
body{background:#f9f7f6;color:#404d5b;font-weight:500;font-size:1.05em;font-family:"Segoe UI","Lucida Grande",Helvetica,Arial,"Microsoft YaHei",FreeSans,Arimo,"Droid Sans","wenquanyi micro hei","Hiragino Sans GB","Hiragino Sans GB W3","FontAwesome",sans-serif;}
a{color:#2fa0ec;text-decoration:none;outline:none;}
a:hover,a:focus{color:#74777b;}
;.container{margin:0 auto;text-align:center;overflow:hidden;}
.content{font-size:150%;padding:3em 0;}
.content h2{margin:0 0 2em;opacity:0.1;}
.content p{margin:1em 0;padding:5em 0 0 0;font-size:0.65em;}
.bgcolor-1{background:#f0efee;}
.bgcolor-2{background:#f9f9f9;}
.bgcolor-3{background:#e8e8e8;}
.bgcolor-4{background:#2f3238;color:#fff;}
.bgcolor-5{background:#df6659;color:#521e18;}
.bgcolor-6{background:#2fa8ec;}
.bgcolor-7{background:#d0d6d6;}
.bgcolor-8{background:#3d4444;color:#fff;}
/* Header */
.htmleaf-header{padding:3em 190px 4em;letter-spacing:-1px;text-align:center;}
.htmleaf-header h1{font-weight:600;font-size:2em;line-height:1;margin-bottom:0;}
.htmleaf-header h1 span{font-family:'Raleway';display:block;font-size:60%;font-weight:400;padding:0.8em 0 0.5em 0;color:#c3c8cd;}
/*nav*/
.htmleaf-demo a{color:#1d7db1;text-decoration:none;}
.htmleaf-demo{width:100%;padding-bottom:1.2em;}
.htmleaf-demo a{display:inline-block;margin:0.5em;padding:0.6em 1em;border:3px solid #1d7db1;font-weight:700;}
.htmleaf-demo a:hover{opacity:0.6;}
.htmleaf-demo a.current{background:#1d7db1;color:#fff;}
/* Top Navigation Style */
.htmleaf-links{position:relative;display:inline-block;white-space:nowrap;font-size:1.5em;text-align:center;}
.htmleaf-links::after{position:absolute;top:0;left:50%;margin-left:-1px;width:2px;height:100%;background:#dbdbdb;content:'';-webkit-transform:rotate3d(0,0,1,22.5deg);transform:rotate3d(0,0,1,22.5deg);}
.htmleaf-icon{display:inline-block;margin:0.5em;padding:0em 0;width:1.5em;text-decoration:none;}
.htmleaf-icon span{display:none;}
.htmleaf-icon:before{margin:0 5px;text-transform:none;font-weight:normal;font-style:normal;font-variant:normal;font-family:'icomoon';line-height:1;speak:none;-webkit-font-smoothing:antialiased;}
/* footer */
.htmleaf-footer{width:100%;padding-top:10px;}
.htmleaf-small{font-size:0.8em;}
.center{text-align:center;}
/* icomoon */
.icon-home:before{content:"\e600";}
.icon-pacman:before{content:"\e623";}
.icon-users2:before{content:"\e678";}
.icon-bug:before{content:"\e699";}
.icon-eye:before{content:"\e610";}
.icon-eye-blocked:before{content:"\e611";}
.icon-eye2:before{content:"\e612";}
.icon-arrow-up-left3:before{content:"\e72f";}
.icon-arrow-up3:before{content:"\e730";}
.icon-arrow-up-right3:before{content:"\e731";}
.icon-arrow-right3:before{content:"\e732";}
.icon-arrow-down-right3:before{content:"\e733";}
.icon-arrow-down3:before{content:"\e734";}
.icon-arrow-down-left3:before{content:"\e735";}
.icon-arrow-left3:before{content:"\e736";}
@media screen and (max-width:50em){.htmleaf-header{padding:3em 10% 4em;}
.htmleaf-header h1{font-size:2em;}
}
@media screen and (max-width:40em){.htmleaf-header h1{font-size:1.5em;}
}
@media screen and (max-width:30em){.htmleaf-header h1{font-size:1.2em;}
}
附件:下载该文件资源,减少时间成本(增值服务)
留言
该资源可下载
File Source
.rar
115.61 KB
html5特效
最新结算
jquery虚拟键盘中文打字效果js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jquery虚拟键盘中文打字效果js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
HTML5实现CSS滤镜图片切换特效代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
jQuery头像裁剪插件cropbox js代码
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery头像裁剪插件cropbox js代码
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 2.31¥ 状态: 待结算 详细>
CSS3制作3D图片立方体旋转特效
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
jQuery+css3实现信封效果
类型: .rar 金额: CNY 0.29¥ 状态: 待结算 详细>
我们力求给您提供有用的文章,再此基础上,会附加营收资源,不做任何广告,让平台可以更好发展 若您发现您的权利被侵害,或使用了您的版权,请发邮件联系 sunlifel@foxmail.com ggbig觉得 : 不提供源码的文章不是好文章
合作伙伴
联系我们
  • QQ:21499807
  • 邮箱:sunlifel@foxmail.com
  • QQ扫一扫加QQ
    QQ扫一扫
Copyright 2023-2024 ggbig.com·皖ICP备2023004211号-1
打赏文章