2012-11-15 9 views
5

coderwall.comはどのようにバックグラウンドエフェクトを行うのですか?小さな画像を撮り、ぼかして、ビューポートの100%までサイズを変更します。次に例を示します。https://coderwall.com/p/on5ojqCoderwallキャンバスで背景がぼやけて表示

私が試した:

<canvas class="blur" src="https://d3levm2kxut31z.cloudfront.net/assets/locations/Mexico-1c39f581666a50a97c5130e13837ff20.jpg" width="300" height="200"></canvas> 

を次に、以下のCSSを追加しました:

.blur { 
    min-width: 100%; 
    min-height: 100%; 
    position: fixed; 
    top: 0; 
    left: 0; 
    z-index: -2; 
    opacity: 0.7; 
} 

をしかし、それは動作しません。

は、以下のjsFiddlehttp://jsfiddle.net/RDdbt/1/

+2

ます。https:/ /github.com/ceramedia/examples/blob/gh-pages/canvas-blur/v5/canvas-image.js – Paradise

+0

JavaScriptを実装しようとしましたが、エラーが発生しました。ここに更新されたjsFiddle http://jsfiddle.net/RDdbt/3/があります。あなたは問題が見えますか?ありがとう。 – Justin

+0

あなたはこれを理解したことがありますか?私はそれを動作させることができましたが、あなたのjsfiddleの例で使用されたスクリプトではできませんでした。私は元のスクリプトを使用しました...もしあなたが助けを望むなら教えてください! –

答えて

7

はこれを試してみてください参照:効果はあなたが彼らのスクリプトをチェックする場合は、このリンクを見つけるでしょう、CSSが、JSとは関係ありません

var CanvasImage=function(e,t){ 
    this.image=t, 
    this.element=e, 
    this.element.width=this.image.width, 
    this.element.height=this.image.height; 
    var n=navigator.userAgent.toLowerCase().indexOf("chrome")>-1, 
    r=navigator.appVersion.indexOf("Mac")>-1; 
    n&&r&&(this.element.width=Math.min(this.element.width,300),this.element.height=Math.min(this.element.height,200)), 
    this.context=this.element.getContext("2d"), 
    this.context.drawImage(this.image,0,0) 
}; 

CanvasImage.prototype={ 
    blur:function(e){ 
     this.context.globalAlpha=.5; 
     for(var t=-e;t<=e;t+=2) 
      for(var n=-e;n<=e;n+=2) 
       this.context.drawImage(this.element,n,t), 
      n>=0&&t>=0&&this.context.drawImage(this.element,-(n-1),-(t-1)); 
      this.context.globalAlpha=1 
     } 
}, 

$(function(){ 
    var image,canvasImage,canvas; 
    $(".blur").each(function(){ 
     canvas=this, 
     image=new Image, 
     image.onload=function(){ 
      canvasImage=new CanvasImage(canvas,this), 
      canvasImage.blur(4) 
     }, 
     image.src=$(this).attr("src"); 
    }); 
}); 

http://jsfiddle.net/RDdbt/6/

関連する問題