
< svg width ="100%" height ="100%" version ="1.1"
xmlns ="http://www.w3.org/2000/svg" >
< defs >
< filter id ="Gaussian_Blur" >
< feGaussianBlur in ="SourceGraphic" stdDeviation ="3" />
</ filter >
</ defs >
< ellipse cx ="200" cy ="150" rx ="70" ry ="40"
style ="fill:#ff0000;stroke:#000000;
stroke-width:2;filter:url(#Gaussian_Blur)" />
</ svg >
* This source code was highlighted with Source Code Highlighter .
< span class ="blurImageContainer" >
< img class ="blurImage" src ="a.jpg" >
</ span >
* This source code was highlighted with Source Code Highlighter .var SVG = {
//
svgns: 'http://www.w3.org/2000/svg' ,
xlink: 'http://www.w3.org/1999/xlink' ,
// svg (name - , attrs - )
createElement: function (name, attrs){
var element = document .createElementNS(SVG.svgns, name);
if (attrs) {
SVG.setAttr(element, attrs);
}
return element;
},
// (element - SVG-)
setAttr: function (element, attrs) {
for ( var i in attrs) {
if (i === 'href' ) { // href xlink
element.setAttributeNS(SVG.xlink, i, attrs[i]);
} else { //
element.setAttribute(i, attrs[i]);
}
}
}
}
* This source code was highlighted with Source Code Highlighter .This is all we need to correctly create several svg elements.var blurredId = Math.random(); //
...
$ this .children( '[id^="blurred"]' ).remove(); //
...
svg = SVG.createElement( 'svg' , {
...
id: 'blurred' +blurredId
});
* This source code was highlighted with Source Code Highlighter .This will allow us to also avoid the conflict of ITDs of the blur filter to which the image refers.var svg, filterId, filter, gaussianBlur, image;
svg = SVG.createElement( 'svg' , { // SVG
xmlns: SVG.svgns,
version: '1.1' ,
//
width: imgWidth,
height: imgHeight,
id: 'blurred' +blurredId
});
filterId = 'blur' +blurredId; // ; image
filter = SVG.createElement( 'filter' , { //
id:filterId
});
gaussianBlur = SVG.createElement( 'feGaussianBlur' , { //
'in' : 'SourceGraphic' , //in — ; ,
stdDeviation: args.deviation // (int)
});
image = SVG.createElement( 'image' , { //,
x: 0,
y: 0,
//,
width: imgWidth,
height: imgHeight,
href: imgSrc,
style: 'filter:url(#' +filterId+ ')' //
});
filter.appendChild(gaussianBlur); //
svg.appendChild(filter); // SVG
svg.appendChild(image); // SVG
this .appendChild(svg); // SVG span ( this )
* This source code was highlighted with Source Code Highlighter .< svg xmlns ="http://www.w3.org/2000/svg" version ="1.1" width ="144" height ="144" id ="blurred0.9918661566916853" >
< filter id ="blur0.9918661566916853" >
< feGaussianBlur in ="SourceGraphic" stdDeviation ="2" ></ feGaussianBlur >
</ filter >
< image x ="0" y ="0" width ="144" height ="144" href ="a.jpg" style ="filter:url(#blur0.9918661566916853)" ></ image >
</ svg >
* This source code was highlighted with Source Code Highlighter .$img.clone() //
.css({ //
// ; ,
filter: 'progid:DXImageTransform.Microsoft.Blur(pixelradius=' + args.deviation*2 + ')' ,
// ,
top: -args.deviation*2,
left: -args.deviation*2,
//- ;
width: imgWidth,
height: imgHeight,
})
.attr( 'id' , 'blurred' +blurredId)
.appendTo( this );
* This source code was highlighted with Source Code Highlighter .jQuery(window).load( function ($){ // , load ready
$( '.blurImageContainer .blurImage' ).css({opacity: 0}); //
$( '.blurImageContainer' ).gaussianBlur({
deviation: 3, //
imageClass: 'blurImage' //
});
$( '.blurImageContainer' ).hover( function (){
$( '.blurImage' , this ).animate({opacity: 1}, 500);
}, function (){
$( '.blurImage' , this ).animate({opacity: 0}, 500);
});
});
* This source code was highlighted with Source Code Highlighter .Source: https://habr.com/ru/post/123035/
All Articles