2014-02-06 9 views
2

HTML에서 색상이 지정된 div의 큰 텍스트로 마스크 유형 효과를 얻으려고합니다. 이 마스크 된 텍스트가 div 뒤에있는 이미지의 일부를 표시하기를 원합니다. 하나; background-clip 속성과 background-image을 div 자체에 사용하는 대신, 요소 밑에있는 것이 무엇인지 (내 경우에는 이미지) 밝히기를 바라고 있습니다. 복합 경로와 함께 svg 이미지를 사용해 보았지만 처리하기가 너무 어려웠습니다. 내가 할 수있는 다른 방법이 있습니까? CSS? jQuery 플러그인? A not-so-successful attempt with svg텍스트를 마스크로 사용하는 CSS div

+1

http://css-tricks.com/image-under-text/ – j08691

+0

을 , 도움이 -하지만 내가 뭘 찾고 있어요. 나는 그 밑에있는 것을 드러내 기위한 텍스트가 필요하다. 배경 이미지를 제공하지 않으려 고합니다. – grevin123

+0

그 아래에 다른 이미지가 어떻게 있을까요? – helion3

답변

2

this article for applying a text mask을 기준으로 캔버스 태그로이 작업을 수행 할 수 있습니다.

<div id="bg"><canvas id="overlay" width="240" height="70"></canvas></div> 
<script> 
// Get a handle to our canvas 
var ctx = document.getElementById('overlay').getContext("2d"); 

// Choose font 
ctx.font = "Bold 36px 'Helvetica'"; 

// Draw black rectangle 
ctx.fillStyle = "black"; 
ctx.fillRect(0,0,230,70); 

// Punch out the text! 
ctx.globalCompositeOperation = 'destination-out'; 
ctx.fillText("Some Text", 25, 50); 
</script> 

http://jsfiddle.net/6aVGU/

+0

유망 해 보입니다. 감사합니다! 캔버스 내에서 블랙 박스의 높이를 움직일 수 있습니까? – grevin123

+0

d3, 사용 가능한 최고의 JavaScript 그래픽 라이브러리를 고려해보십시오. – royhowie

-2

텍스트의 투명한 PNG 이미지로이 작업을 수행 할 수 있습니다.

+0

다른 것을 찾을 수 없다면이 작업을 수행 할 것입니다.하지만 텍스트를 쉽게 편집 할 수있는 솔루션을 원합니다 :) 감사합니다. – grevin123

1

캔버스 객체를 사용하여 할 수있는 :이 본 http://jsfiddle.net/JackKalish/g3BDa/3/

var canvas1 = document.getElementById("canvas1"); 
    var canvasContext1 = canvas1.getContext("2d"); 

    // destination-out 
    // Text cuts-out everything under it 
    // background is revealed in the cut-out 
    makeGradientAndFont(canvasContext1, canvas1); 
    canvasContext1.globalCompositeOperation = 'destination-out'; 
    canvasContext1.fillText("Portfolio", 175, 50); 

    function makeGradientAndFont(ctx, canvas) { 
     var grad = ctx.createLinearGradient(0, 0, canvas.width, canvas.height); 
     grad.addColorStop(0, '#0000FF'); 
     grad.addColorStop(.3, '#00FFFF'); 
     grad.addColorStop(.4, '#99FFFF'); 
     grad.addColorStop(.5, '#00FF00'); 
     grad.addColorStop(.6, '#FFFF00'); 
     grad.addColorStop(.8, '#F00000'); 
     ctx.rect(0, 0, canvas.width, canvas.height); 
     ctx.fillStyle = grad; 
     ctx.fill(); 
     ctx.fillStyle = "black"; 
     ctx.font = "55px Arial"; 
     ctx.textAlign = "center"; 
     ctx.textBaseline = "middle"; 
    } 
+0

감사합니다! 이것은 또한 내가 바라는 것과 비슷하게 보입니다 :) – grevin123

관련 문제