Skip to main content
deleted 243 characters in body
Source Link
m4n0
  • 32.6k
  • 28
  • 81
  • 98

Here an ugly implementation in canvas. I tried this solution, but the results are worse than I expected, so here it is anyway.

Canvas example

 $("div").each(function() {   var CHARS = $(this).text().split('');   $(this).html("");   $.each(CHARS, function(index, char) {   var canvas = $("<canvas />")   .css("width", "40px")   .css("height", "40px")   .get(0);   $("div").append(canvas);   var ctx = canvas.getContext("2d");   var gradient = ctx.createLinearGradient(0, 0, 130, 0);   gradient.addColorStop("0", "blue");   gradient.addColorStop("0.5", "blue");   gradient.addColorStop("0.51", "red");   gradient.addColorStop("1.0", "red");   ctx.font = '130pt Calibri';   ctx.fillStyle = gradient;   ctx.fillText(char, 10, 130);   });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div>Example Text</div>

Here an ugly implementation in canvas. I tried this solution, but the results are worse than I expected, so here it is anyway.

Canvas example

 $("div").each(function(){   var CHARS = $(this).text().split('');   $(this).html("");   $.each(CHARS,function(index, char){   var canvas = $("<canvas />")   .css("width", "40px")   .css("height", "40px")   .get(0);   $("div").append(canvas);   var ctx = canvas.getContext("2d");   var gradient = ctx.createLinearGradient(0, 0, 130, 0);   gradient.addColorStop("0", "blue");   gradient.addColorStop("0.5", "blue");   gradient.addColorStop("0.51", "red");   gradient.addColorStop("1.0", "red");   ctx.font = '130pt Calibri';   ctx.fillStyle = gradient;   ctx.fillText(char, 10, 130);   });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div>Example Text</div>

Here an ugly implementation in canvas. I tried this solution, but the results are worse than I expected, so here it is anyway.

Canvas example

$("div").each(function() { var CHARS = $(this).text().split(''); $(this).html(""); $.each(CHARS, function(index, char) { var canvas = $("<canvas />") .css("width", "40px") .css("height", "40px") .get(0); $("div").append(canvas); var ctx = canvas.getContext("2d"); var gradient = ctx.createLinearGradient(0, 0, 130, 0); gradient.addColorStop("0", "blue"); gradient.addColorStop("0.5", "blue"); gradient.addColorStop("0.51", "red"); gradient.addColorStop("1.0", "red"); ctx.font = '130pt Calibri'; ctx.fillStyle = gradient; ctx.fillText(char, 10, 130); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div>Example Text</div>

Example code into a snippet
Source Link
Fiambre
  • 2k
  • 13
  • 23

http://jsfiddle.net/kLXmL/2/

 $("div").each(function(){ var CHARS = $(this).text().split(''); $(this).html(""); $.each(CHARS,function(index, char){ var canvas = $("<canvas />") .css("width", "40px") .css("height", "40px") .get(0); $("div").append(canvas); var ctx = canvas.getContext("2d"); var gradient = ctx.createLinearGradient(0, 0, 130, 0); gradient.addColorStop("0", "blue"); gradient.addColorStop("0.5", "blue"); gradient.addColorStop("0.51", "red"); gradient.addColorStop("1.0", "red"); ctx.font = '130pt Calibri'; ctx.fillStyle = gradient; ctx.fillText(char, 10, 130); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div>Example Text</div>
<div>Example Text</div> $(function(){ $("div").each(function(){ var CHARS = $(this).text().split(''); $(this).html(""); $.each(CHARS,function(index, char){ var canvas = $("<canvas />") .css("width", "40px") .css("height", "40px") .get(0); $("div").append(canvas); var ctx = canvas.getContext("2d"); var gradient = ctx.createLinearGradient(0, 0, 130, 0); gradient.addColorStop("0", "blue"); gradient.addColorStop("0.5", "blue"); gradient.addColorStop("0.51", "red"); gradient.addColorStop("1.0", "red"); ctx.font = '130pt Calibri'; ctx.fillStyle = gradient; ctx.fillText(char, 10, 130); }); }); }); 
 

http://jsfiddle.net/kLXmL/2/

<div>Example Text</div> $(function(){ $("div").each(function(){ var CHARS = $(this).text().split(''); $(this).html(""); $.each(CHARS,function(index, char){ var canvas = $("<canvas />") .css("width", "40px") .css("height", "40px") .get(0); $("div").append(canvas); var ctx = canvas.getContext("2d"); var gradient = ctx.createLinearGradient(0, 0, 130, 0); gradient.addColorStop("0", "blue"); gradient.addColorStop("0.5", "blue"); gradient.addColorStop("0.51", "red"); gradient.addColorStop("1.0", "red"); ctx.font = '130pt Calibri'; ctx.fillStyle = gradient; ctx.fillText(char, 10, 130); }); }); }); 

 $("div").each(function(){ var CHARS = $(this).text().split(''); $(this).html(""); $.each(CHARS,function(index, char){ var canvas = $("<canvas />") .css("width", "40px") .css("height", "40px") .get(0); $("div").append(canvas); var ctx = canvas.getContext("2d"); var gradient = ctx.createLinearGradient(0, 0, 130, 0); gradient.addColorStop("0", "blue"); gradient.addColorStop("0.5", "blue"); gradient.addColorStop("0.51", "red"); gradient.addColorStop("1.0", "red"); ctx.font = '130pt Calibri'; ctx.fillStyle = gradient; ctx.fillText(char, 10, 130); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div>Example Text</div>
 

Copy edited. In English, the subjective form of the singular first-person pronoun, "I", is capitalized, along with all its contractions such as I'll and I'm.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

Here an ugly implementation in canvas, i try. I tried this solution, but the results are worse than iI expected, so here it is anyway.

Canvas example

http://jsfiddle.net/kLXmL/2/

<div>Example Text</div> $(function(){  $("div").each(function(){ var CHARS = $(this).text().split(''); $(this).html(""); $.each(CHARS,function(index, char){ var canvas = $("<canvas />") .css("width", "40px") .css("height", "40px") .get(0); $("div").append(canvas); var ctx = canvas.getContext("2d"); var gradient=ctxgradient = ctx.createLinearGradient(0, 0, 130, 0); gradient.addColorStop("0", "blue"); gradient.addColorStop("0.5", "blue"); gradient.addColorStop("0.51", "red"); gradient.addColorStop("1.0", "red"); ctx.font = '130pt Calibri'; ctx.fillStyle=gradient; fillStyle = gradient; ctx.fillText(char, 10, 130); });       });  }); 

Here an ugly implementation in canvas, i try this solution but the results are worse than i expected, so here is anyway.

Canvas example

http://jsfiddle.net/kLXmL/2/

<div>Example Text</div> $(function(){  $("div").each(function(){ var CHARS = $(this).text().split(''); $(this).html(""); $.each(CHARS,function(index,char){ var canvas = $("<canvas />") .css("width","40px") .css("height","40px") .get(0); $("div").append(canvas); var ctx = canvas.getContext("2d"); var gradient=ctx.createLinearGradient(0,0,130,0); gradient.addColorStop("0","blue"); gradient.addColorStop("0.5","blue"); gradient.addColorStop("0.51","red"); gradient.addColorStop("1.0","red"); ctx.font = '130pt Calibri'; ctx.fillStyle=gradient;  ctx.fillText(char,10,130); });       });  }); 

Here an ugly implementation in canvas. I tried this solution, but the results are worse than I expected, so here it is anyway.

Canvas example

http://jsfiddle.net/kLXmL/2/

<div>Example Text</div> $(function(){ $("div").each(function(){ var CHARS = $(this).text().split(''); $(this).html(""); $.each(CHARS,function(index, char){ var canvas = $("<canvas />") .css("width", "40px") .css("height", "40px") .get(0); $("div").append(canvas); var ctx = canvas.getContext("2d"); var gradient = ctx.createLinearGradient(0, 0, 130, 0); gradient.addColorStop("0", "blue"); gradient.addColorStop("0.5", "blue"); gradient.addColorStop("0.51", "red"); gradient.addColorStop("1.0", "red"); ctx.font = '130pt Calibri'; ctx.fillStyle = gradient; ctx.fillText(char, 10, 130); }); }); }); 
Source Link
Fiambre
  • 2k
  • 13
  • 23
Loading