Making angular shapes responsive is a little tricky because you can't use percentages as border
values in your CSS, so I wrote a couple functions to calculate the page width and resize a triangle accordingly. The first calculates the size on loading the page, the second recalculates the size as the page width changes.
CSS:
.triangle {
width: 0;
height: 0;
border-top: 50px solid rgba(255, 255, 0, 1);
border-right: 100px solid transparent;
}
HTML:
<div class="triangle"></div>
JS:
$(document).ready(function () {
var windowWidth = $(window).width();
$(".triangle").css({
"border-top": windowWidth / 2 + 'px solid rgba(255, 255, 0, 1)'
});
$(".triangle").css({
"border-right": windowWidth / 1.5 + 'px solid transparent'
});
});
$(window).resize(function () {
var windowWidthR = $(window).width();
$(".triangle").css({
"border-top": windowWidthR / 2 + 'px solid rgba(255, 255, 0, 1)'
});
$(".triangle").css({
"border-right": windowWidthR / 1.5 + 'px solid transparent'
});
});
Here's a jsFiddle - http://jsfiddle.net/craigcannon/58dVS/17/
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…