In a previous question I had asked if it were possible to individually style half of a character. The response was amazing and there were many great solutions found. You can see the question HERE.
I am now trying to utilize that and do something more advanced.
What I am trying to accomplish:
- I am trying to replace all of the "A"s in the text and replace them with "V"
- Once the A's have become V's I am then rotating the V's 180 degrees.
- The V's will essentially become /\ .
The issue I'm having:
- For some reason, the characters are being duplicated that have the "HalfStyle" applied to them.
You can see a working JSFiddle HERE.
HTML:
<div class="text"> MATT WAS HERE </div>
CSS:
.text{
font-size:100px;
font-family:"Arial", Helvetica, sans-serif;
font-weight:bold;
color: #0C5894;
}
#vflip {
margin:0;
padding:0;
display:inline-block;
-webkit-transform: rotate(180deg);
-moz-transform: rotate(180deg);
-o-transform: rotate(180deg);
-ms-transform: rotate(180deg);
transform: rotate(180deg);
color:#ff0000;
}
.halfStyle {
position:relative;
display:inline-block;
width:1;
font-size:100px;
color: #0C5894;
overflow:hidden;
white-space: pre;
}
.halfStyle:before {
display:block;
z-index:1;
position:absolute;
top:0;
width: 50%;
content: attr(data-content); /* dynamic content for the pseudo element */
overflow:hidden;
color: #6898BC;
}
JQuery:
$(".text").each(function() {
var text = $(this).text();
var flipped = text.split('A').join('<span class="textToHalfStyle" id="vflip">V</span>');
$(this).html(flipped)
});
var textToHalfStyle = $('.textToHalfStyle').text();
var textToHalfStyleChars = textToHalfStyle.split('');
$('.textToHalfStyle').html('');
$.each(textToHalfStyleChars, function(i,v){
$('.textToHalfStyle').append('<span class="halfStyle" data-content="' + v + '">' + v + '</span>');
});
Any idea as to what may be causing this?
Thanks in advance! :)