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 Animated Stroke Dash | 3,623 Kb |
Vue JS Filtering | 9,746 Kb |
SVG Image Blur | 3,893 Kb |
Basic Snap.svg JS Animation | 5,622 Kb |
FitText.js Demo | 1,897 Kb |
Responsive SVG Overlay | 2,674 Kb |
SVG Text Masking | 2,141 Kb |
Custom Stagger Start Point | 4,001 Kb |
Graphs and Snap.svg | 2,870 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 |
Transitioning application screens with semantically named classes | Djgrant | 3,697 Kb |
Static Image to Video Block | Grayghostvisuals | 4,864 Kb |
STAR WARS LIGHTSABER | Francoiscoron | 4,420 Kb |
Hamburger Menu Animation | Salmanraza | 2,580 Kb |
Nav Test -- cats 1 | Payls | 4,735 Kb |
Fellowship of the Ring | Aussieyang | 2,639 Kb |
BSP Dungeon Generation | Xgundam05 | 5,326 Kb |
Flexbox Test | Icutpeople | 2,486 Kb |
Simple, flat contact form | Zeaklous | 2,719 Kb |
Mondrian | Chrisarmstrong | 2,787 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!