1
Hello,
I need to insert a text on top of an image, which is responsive in the correct place of the image, until then it is working "well", but the site is done in bootstrap, and when it comes out of col-Md-4 and goes to the size col-Xs-12 (when resizes the window). From there the text becomes too small.
What I want is that the text adapts to the image, just as the image adapts to the resizing of the window.
Follow jsfiddle with example: https://jsfiddle.net/xuavhmg7/2/
The code I took from this site: http://alt-web.com/TUTORIALS/? id=responsive_text_overlays
Edited: David Samm helped me a lot.
Jsfidlle Updated: https://jsfiddle.net/xuavhmg7/3/
He got a delay when he switched, but acceptable. Maybe if I put 'Else if' for all ['Xs','Sm','Md','lg'] with different font-size values it will smooth the switch.
I added this script to catch the breakpoint of bootstrap3.
<script src="https://rawgit.com/maciej-gurban/responsive-bootstrap-toolkit/master/dist/bootstrap-toolkit.min.js"></script>
And I did that function to change the values.
<script type="text/javascript">
(function($, document, window, viewport){
function setTextSize() {
if ((viewport.current() == 'xs') || (viewport.current() == 'sm')) {
$("figure.overlay figcaption").css('font-size','7.0vw');
} else {
$("figure.overlay figcaption").css('font-size','2.4vw');
}
}
// Executes once whole document has been loaded
$(document).ready(function() {
console.log('Current breakpoint:', viewport.current());
setTextSize();
});
$(window).resize(
viewport.changed(function(){
console.log('Current breakpoint:', viewport.current());
setTextSize();
})
);
})(jQuery, document, window, ResponsiveBootstrapToolkit);
</script>
Very good answer, helped me to redo the code. I edited my post with additional data. And it’s working.
– Carlos Fagiani Jr