2012-11-15 11 views
5

coderwall.com इस पृष्ठभूमि प्रभाव को कैसे कर रहा है, जहां वे एक छोटी छवि लेते हैं, इसे धुंधला करते हैं, और इसे 100% तक व्यूपोर्ट तक आकार देते हैं। यहाँ एक उदाहरण है: https://coderwall.com/p/on5ojqकैनवास के साथ कोडरवॉल धुंधला पृष्ठभूमि प्रभाव धुंधला

मैंने कोशिश की:

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

तो निम्नलिखित सीएसएस कहा:

.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

कि प्रभाव सीएसएस लेकिन js से संबंधित नहीं है, अगर आप अपने स्क्रिप्ट की जाँच आप इस लिंक मिलेगा https://github.com/ceramedia/examples/blob/gh-pages/canvas-blur/v5/canvas-image.js – Paradise

+0

जावास्क्रिप्ट को कार्यान्वित करने का प्रयास किया, लेकिन एक त्रुटि प्राप्त हुई। यहां अपडेट किया गया jsFiddle http://jsfiddle.net/RDdbt/3/ है। क्या आप समस्या को देखते हैं? धन्यवाद। – Justin

+0

क्या आपने कभी यह पता लगाया है? मैं इसे काम करने में सक्षम था लेकिन आपके jsfiddle उदाहरण में इस्तेमाल लिपि के साथ नहीं। मैंने मूल लिपि का उपयोग किया ... अगर आपको मदद चाहिए तो मुझे बताएं! –

उत्तर

7

इस प्रयास करें:

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/

संबंधित मुद्दे