Responsive SVG Overlay

Size
2,674 Kb
Views
50,600

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 Previews

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();
});
Responsive SVG Overlay - Script Codes
Responsive SVG Overlay - Script Codes
Home Page Home
Developer Jon Christensen
Username JMChristensen
Uploaded August 03, 2022
Rating 3
Size 2,674 Kb
Views 50,600
Do you need developer help for Responsive SVG Overlay?

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!

Jon Christensen (JMChristensen) Script Codes
Create amazing blog posts with AI!

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!