в html верх
Код:
<script type="text/javascript"> document.getelementsbyclassname = function(classname) { var children = document.getelementsbytagname('*') || document.all; var elements = new array(); for (var i = 0; i < children.length; i++) { var child = children[i]; var classnames = child.classname.split(' '); for (var j = 0; j < classnames.length; j++) { if (classnames[j] == classname) { elements.push(child); break; } } } return elements; } var reflection = { defaultheight : 0.5, defaultopacity: 0.5, add: function(image, options) { reflection.remove(image); doptions = { "height" : reflection.defaultheight, "opacity" : reflection.defaultopacity } if (options) { for (var i in doptions) { if (!options[i]) { options[i] = doptions[i]; } } } else { options = doptions; } try { var d = document.createelement('div'); var p = image; var classes = p.classname.split(' '); var newclasses = ''; for (j=0;j<classes.length;j++) { if (classes[j] != "reflect") { if (newclasses) { newclasses += ' ' } newclasses += classes[j]; } } var reflectionheight = math.floor(p.height*options['height']); var divheight = math.floor(p.height*(1+options['height'])); var reflectionwidth = p.width; if (document.all && !window.opera) { /* fix hyperlinks */ if(p.parentelement.tagname == 'a') { var d = document.createelement('a'); d.href = p.parentelement.href; } /* copy original image's classes & styles to div */ d.classname = newclasses; p.classname = 'reflected'; d.style.csstext = p.style.csstext; p.style.csstext = 'vertical-align: bottom'; var reflection = document.createelement('img'); reflection.src = p.src; reflection.style.width = reflectionwidth+'px'; reflection.style.marginbottom = "-"+(p.height-reflectionheight)+'px'; reflection.style.filter = 'flipv progid:dximagetransform.microsoft.alpha(opacity='+(options['opacity']*100)+', style=1, finishopacity=0, startx=0, starty=0, finishx=0, finishy='+(options['height']*100)+')'; d.style.width = reflectionwidth+'px'; d.style.height = divheight+'px'; p.parentnode.replacechild(d, p); d.appendchild(p); d.appendchild(reflection); } else { var canvas = document.createelement('canvas'); if (canvas.getcontext) { /* copy original image's classes & styles to div */ d.classname = newclasses; p.classname = 'reflected'; d.style.csstext = p.style.csstext; p.style.csstext = 'vertical-align: bottom'; var context = canvas.getcontext("2d"); canvas.style.height = reflectionheight+'px'; canvas.style.width = reflectionwidth+'px'; canvas.height = reflectionheight; canvas.width = reflectionwidth; d.style.width = reflectionwidth+'px'; d.style.height = divheight+'px'; p.parentnode.replacechild(d, p); d.appendchild(p); d.appendchild(canvas); context.save(); context.translate(0,image.height-1); context.scale(1,-1); context.drawimage(image, 0, 0, reflectionwidth, image.height); context.restore(); context.globalcompositeoperation = "destination-out"; var gradient = context.createlineargradient(0, 0, 0, reflectionheight); gradient.addcolorstop(1, "rgba(255, 255, 255, 1.0)"); gradient.addcolorstop(0, "rgba(255, 255, 255, "+(1-options['opacity'])+")"); context.fillstyle = gradient; if (navigator.appversion.indexof('webkit') != -1) { context.fill(); } else { context.fillrect(0, 0, reflectionwidth, reflectionheight*2); } } } } catch (e) { } }, remove : function(image) { if (image.classname == "reflected") { image.classname = image.parentnode.classname; image.parentnode.parentnode.replacechild(image, image.parentnode); } } } function addreflections() { var rimages = document.getelementsbyclassname('reflect'); for (i=0;i<rimages.length;i++) { var rheight = null; var ropacity = null; var classes = rimages[i].classname.split(' '); for (j=0;j<classes.length;j++) { if (classes[j].indexof("rheight") == 0) { var rheight = classes[j].substring(7)/100; } else if (classes[j].indexof("ropacity") == 0) { var ropacity = classes[j].substring(8)/100; } } reflection.add(rimages[i], { height: rheight, opacity : ropacity}); } } var previousonload = window.onload; window.onload = function () { if(previousonload) previousonload(); addreflections(); } </script>
в html низ
Код:
<script type="text/javascript"> document.getelementsbyclassname = function(classname) { var children = document.getelementsbytagname('*') || document.all; var elements = new array(); for (var i = 0; i < children.length; i++) { var child = children[i]; var classnames = child.classname.split(' '); for (var j = 0; j < classnames.length; j++) { if (classnames[j] == classname) { elements.push(child); break; } } } return elements; } var reflection = { defaultheight : 0.5, defaultopacity: 0.5, add: function(image, options) { reflection.remove(image); doptions = { "height" : reflection.defaultheight, "opacity" : reflection.defaultopacity } if (options) { for (var i in doptions) { if (!options[i]) { options[i] = doptions[i]; } } } else { options = doptions; } try { var d = document.createelement('div'); var p = image; var classes = p.classname.split(' '); var newclasses = ''; for (j=0;j<classes.length;j++) { if (classes[j] != "reflect") { if (newclasses) { newclasses += ' ' } newclasses += classes[j]; } } var reflectionheight = math.floor(p.height*options['height']); var divheight = math.floor(p.height*(1+options['height'])); var reflectionwidth = p.width; if (document.all && !window.opera) { /* fix hyperlinks */ if(p.parentelement.tagname == 'a') { var d = document.createelement('a'); d.href = p.parentelement.href; } /* copy original image's classes & styles to div */ d.classname = newclasses; p.classname = 'reflected'; d.style.csstext = p.style.csstext; p.style.csstext = 'vertical-align: bottom'; var reflection = document.createelement('img'); reflection.src = p.src; reflection.style.width = reflectionwidth+'px'; reflection.style.marginbottom = "-"+(p.height-reflectionheight)+'px'; reflection.style.filter = 'flipv progid:dximagetransform.microsoft.alpha(opacity='+(options['opacity']*100)+', style=1, finishopacity=0, startx=0, starty=0, finishx=0, finishy='+(options['height']*100)+')'; d.style.width = reflectionwidth+'px'; d.style.height = divheight+'px'; p.parentnode.replacechild(d, p); d.appendchild(p); d.appendchild(reflection); } else { var canvas = document.createelement('canvas'); if (canvas.getcontext) { /* copy original image's classes & styles to div */ d.classname = newclasses; p.classname = 'reflected'; d.style.csstext = p.style.csstext; p.style.csstext = 'vertical-align: bottom'; var context = canvas.getcontext("2d"); canvas.style.height = reflectionheight+'px'; canvas.style.width = reflectionwidth+'px'; canvas.height = reflectionheight; canvas.width = reflectionwidth; d.style.width = reflectionwidth+'px'; d.style.height = divheight+'px'; p.parentnode.replacechild(d, p); d.appendchild(p); d.appendchild(canvas); context.save(); context.translate(0,image.height-1); context.scale(1,-1); context.drawimage(image, 0, 0, reflectionwidth, image.height); context.restore(); context.globalcompositeoperation = "destination-out"; var gradient = context.createlineargradient(0, 0, 0, reflectionheight); gradient.addcolorstop(1, "rgba(255, 255, 255, 1.0)"); gradient.addcolorstop(0, "rgba(255, 255, 255, "+(1-options['opacity'])+")"); context.fillstyle = gradient; if (navigator.appversion.indexof('webkit') != -1) { context.fill(); } else { context.fillrect(0, 0, reflectionwidth, reflectionheight*2); } } } } catch (e) { } }, remove : function(image) { if (image.classname == "reflected") { image.classname = image.parentnode.classname; image.parentnode.parentnode.replacechild(image, image.parentnode); } } } function addreflections() { var rimages = document.getelementsbyclassname('reflect'); for (i=0;i<rimages.length;i++) { var rheight = null; var ropacity = null; var classes = rimages[i].classname.split(' '); for (j=0;j<classes.length;j++) { if (classes[j].indexof("rheight") == 0) { var rheight = classes[j].substring(7)/100; } else if (classes[j].indexof("ropacity") == 0) { var ropacity = classes[j].substring(8)/100; } } reflection.add(rimages[i], { height: rheight, opacity : ropacity}); } } var previousonload = window.onload; window.onload = function () { if(previousonload) previousonload(); addreflections(); } </script>