Responsive SVG Overlay
How do I make an responsive svg overlay?
Uses Raphael.js with an image to dynamically resize the overlay on the image for crisp overlay graphic at any size.. What is a responsive svg overlay? How do you make a responsive svg overlay? This script and codes were developed by Jon Christensen on 03 August 2022, Wednesday.
Responsive SVG Overlay - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Responsive SVG Overlay</title> <script src="http://s.codepen.io/assets/libs/modernizr.js" type="text/javascript"></script> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <style> /* NOTE: The styles were added inline because Prefixfree needs access to your styles and they must be inlined if they are on local disk! */
html { font-size: 62.5%;
}
#container { background: #CCC; display: block; width: 100%; height: auto; position: relative;
}
#container img { max-width: 100%; height: auto; display: block; position: static;
}
.info { display: none; position: absolute; top: 50%; left: 10%; font-size: 3rem; z-index: 11;
}
#canvas-cont { display: block; width: 100%; height: 100%; overflow: hidden; position: absolute; top: 0; left: 0; z-index: 10;
}
#canvas { height: 100%; width: 100%;
} </style> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script>
</head>
<body> <div id="container"> <div id="canvas-cont"> <div id="canvas"></div> </div> <div class="slide"> <img src="http://lorempixel.com/1500/480/city/1" /> <div class="info"> <p><a href="http://www.google.com">Google</a></p> </div> </div>
</div> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='http://github.com/DmitryBaranovskiy/raphael/raw/master/raphael-min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Responsive SVG Overlay - Script Codes CSS Codes
html { font-size: 62.5%;
}
#container { background: #CCC; display: block; width: 100%; height: auto; position: relative;
}
#container img { max-width: 100%; height: auto; display: block; position: static;
}
.info { display: none; position: absolute; top: 50%; left: 10%; font-size: 3rem; z-index: 11;
}
#canvas-cont { display: block; width: 100%; height: 100%; overflow: hidden; position: absolute; top: 0; left: 0; z-index: 10;
}
#canvas { height: 100%; width: 100%;
}
Responsive SVG Overlay - Script Codes JS Codes
var
canvas = $('#canvas'), paper = Raphael('canvas', 1500, 480);
var
triangle1 = paper.path('M0,480 H1500 V420 L0,480'), triangle2 = paper.path('M1500,0 H0 V40 L1500,0');
triangle1.attr({ 'fill': '#fff', 'stroke': '#fff', 'stroke-width': 1
});
triangle2.attr({ 'fill': '#fff', 'stroke': '#fff', 'stroke-width': 1
});
// Resizing function
function resizePaper() { var win = $(window), scale = win.width() / 1500; if (win.width() > 1500) { scale = 1; } var calc = 's' + scale + ',' + scale + ',0,0'; triangle1.transform(calc); triangle2.transform(calc); paper.renderfix()
}
// Resize right away and when the user resizes the viewport
resizePaper();
$(window).resize(function() { resizePaper();
});
Developer | Jon Christensen |
Username | JMChristensen |
Uploaded | August 03, 2022 |
Rating | 3 |
Size | 2,674 Kb |
Views | 50,600 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Table Cell Slideshow | 2,892 Kb |
SVG Image Blur | 3,893 Kb |
Custom Stagger Start Point | 4,001 Kb |
Raphael SVG Circle Timer | 2,216 Kb |
Panel Navigation | 4,288 Kb |
Section Diagonal Areas | 2,810 Kb |
Google Button Ripple | 3,524 Kb |
3D Cube | 2,543 Kb |
FitText.js Demo | 1,897 Kb |
CSS Banners | 2,548 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Base-Style | Daniel_gooss | 2,614 Kb |
Dribbble Inspired Registration Form | Lancebush | 2,358 Kb |
Jochaho Skeleton | Dhanushbadge | 1,689 Kb |
Tab panels | Accessibility | 0 Kb |
BabyStore | Pablo-Ai | 3,807 Kb |
Table Exercise | Fresco | 9,585 Kb |
Project MMetro beta | Atomicsong | 5,157 Kb |
Motion Lines - codevember - 02 - 2016 | Caiocares | 2,744 Kb |
Three js | Paulq | 2,353 Kb |
HTM5 picture dropzone | Jaysalvat | 2,576 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!