大佬教程收集整理的这篇文章主要介绍了html5 – 使用CSS3可以创建这种图像屏蔽效果吗?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
HTML
<canvas id="canvas1" width="400" height="400"></canvas>
使用Javascript
var can = document.getElementById('canvas1'); var ctx = can.getContext('2d'); can.addEventListener('mousemove',function(E) { var mouse = getMouse(e,can); redraw(mousE); },falsE); function redraw(mousE) { console.log('a'); can.width = can.width; ctx.drawImage(img,0); ctx.beginPath(); ctx.rect(0,500,500); ctx.arc(mouse.x,mouse.y,70,Math.PI*2,truE) ctx.clip(); ctx.drawImage(img2,0); } var img = new Image(); img.onload = function() { redraw({x: -450,y: -500}) } img.src = 'http://placekitten.com/400/400'; var img2 = new Image(); img2.onload = function() { redraw({x: -450,y: -500}) } img2.src = 'http://placekitten.com/400/395'; function getMouse(e,canvas) { var element = canvas,offsetX = 0,offsetY = 0,mx,my; if (element.offsetParent !== undefined) { do { offsetX += element.offsetLeft; offsetY += element.offsetTop; } while ((element = element.offsetParent)); } mx = e.pageX - offsetX; my = e.pageY - offsetY; return { x: mx,y: my }; }
http://jsfiddle.net/maackle/66uCs/
HTML
<div class="masker"> <img class="base" src="http://lorempixel.com/400/400/cats/1" /> <div class="overlay"></div> </div>
CSS
.masker { position: relative; } .overlay { position: absolute; display: none; width: 100px; height: 100px; border-radius: 50%; BACkground: url(http://lorempixel.com/400/400/cats/2) no-repeat; }
jQuery 1.10.1
$('.masker').on('mousemove',function (E) { var r,x,y,top,left,bottom,right,attr,$base,$overlay; r = 100; $base = $(this).find('.base'); $overlay = $(this).find('.overlay'); x = e.pageX - $base.offset().left; y = e.pageY - $base.offset().top; top = y - r / 2; left = x - r / 2; if (x < 0 || y < 0 || x > $base.width() || y > $base.height()) { $overlay.hide(); } else { $overlay.show().css({ 'BACkground-position': '' + (-left) + 'px ' + (-top) + 'px','left': left,'top': top }); } }); //just for good measure $('.masker').on('mouSEOut',function (E) { $(this).find('.overlay').hide(); });
以上是大佬教程为你收集整理的html5 – 使用CSS3可以创建这种图像屏蔽效果吗?全部内容,希望文章能够帮你解决html5 – 使用CSS3可以创建这种图像屏蔽效果吗?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。