jQuery translate text strings using an animation? -


i have text, have translations in 15 languages, i'm trying think if possible, i'd have button , when click it, animate string being translated letter letter start off hello , click it goes bonjour , animate transition.

is possible using jquery animations?

edit: noticed post >> it animate string being translated letter letter <<

i not sure how can map letter what. for ex: hello -> bonjour - how map letter h. imagine how long take whole page translated..

i suggest use simple animation fadeout / fadein on whole text better user too. see below,

markup:

<div id="test">hello</div> <button>translate</button> 

js:

$('button').click (function () {     $('#test').fadeout(500, function () {        $(this).html('bonjour').fadein(300);     }); }); 

demo

edit: below code rough version of gradient fading. order of animation below,

  1. animate opacity of content 1 0.
  2. show overlay , increase width of overlay 10 width of content give shutter effect. background of overlay gradient transparent give gradient fading effect.
  3. update translated message content , animate opacity of content 0 1.
  4. animate overlay width width of content 0 , hide.

the effect still not graceful, code should work fine.. may need adjust css (see instruction below) , animation delays effect like.

demo: http://jsfiddle.net/9dq3u/7/ (adjust duration understand how works)

$(function() {     var $test = $('#test');     var $overlay = $('.overlay');      var tmsg = 'bonjour<p>c\'est le message de test</p><p>pour démontrer l\'effet de fondu</p>';      $overlay.css({         'width': 10,         'height': $test.outerheight()     }).position({             of: $test,             my: 'left top',             at: 'left top'     });      $('button').click(function() {          $test.animate({             opacity: 0         }, 1000);          $overlay.show().animate({             'width': ($test.width() + $test.width()/2) //adjust need         }, 600, function() {              $overlay.css('width', $test.width()); //adjust need              $test.html(tmsg).animate({                 'opacity': 1             }, 200);             $overlay.animate({                 'width': 0             }, 1500, function() {                 $(this).hide();             });                     });     }); }); 

also below css gradient transparent background overlay:

/* ie9 svg, needs conditional override of 'filter' 'none' */ background: url(data:image/svg+xml;base64,pd94bwwgdmvyc2lvbj0ims4wiia/pgo8c3znihhtbg5zpsjodhrwoi8vd3d3lnczlm9yzy8ymdawl3n2zyigd2lkdgg9ijewmcuiighlawdodd0imtawjsigdmlld0jved0imcawidegmsigchjlc2vydmvbc3bly3rsyxrpbz0ibm9uzsi+ciagpgxpbmvhckdyywrpzw50iglkpsjncmfklxvjz2ctz2vuzxjhdgvkiibncmfkawvudfvuaxrzpsj1c2vyu3bhy2vpblvzzsigede9ijaliib5mt0imcuiihgypsixmdaliib5mj0imcuipgogicagphn0b3agb2zmc2v0psiwjsigc3rvcc1jb2xvcj0ii2zmzmzmziigc3rvcc1vcgfjaxr5psixii8+ciagica8c3rvccbvzmzzzxq9ijiwjsigc3rvcc1jb2xvcj0ii2zmzmzmziigc3rvcc1vcgfjaxr5psixii8+ciagica8c3rvccbvzmzzzxq9ijm4jsigc3rvcc1jb2xvcj0ii2zmzmzmziigc3rvcc1vcgfjaxr5psixii8+ciagica8c3rvccbvzmzzzxq9ijewmcuiihn0b3aty29sb3i9iinmzmzmzmyiihn0b3atb3bhy2l0et0imcivpgogidwvbgluzwfyr3jhzgllbnq+ciagphjly3qged0imciget0imcigd2lkdgg9ijeiighlawdodd0imsigzmlsbd0idxjskcnncmfklxvjz2ctz2vuzxjhdgvkksiglz4kpc9zdmc+); background: -moz-linear-gradient(left,  rgba(255,255,255,1) 0%, rgba(255,255,255,1) 20%, rgba(255,255,255,1) 38%, rgba(255,255,255,0) 100%); /* ff3.6+ */ background: -webkit-gradient(linear, left top, right top, color-stop(0%,rgba(255,255,255,1)), color-stop(20%,rgba(255,255,255,1)), color-stop(38%,rgba(255,255,255,1)), color-stop(100%,rgba(255,255,255,0))); /* chrome,safari4+ */ background: -webkit-linear-gradient(left,  rgba(255,255,255,1) 0%,rgba(255,255,255,1) 20%,rgba(255,255,255,1) 38%,rgba(255,255,255,0) 100%); /* chrome10+,safari5.1+ */ background: -o-linear-gradient(left,  rgba(255,255,255,1) 0%,rgba(255,255,255,1) 20%,rgba(255,255,255,1) 38%,rgba(255,255,255,0) 100%); /* opera 11.10+ */ background: -ms-linear-gradient(left,  rgba(255,255,255,1) 0%,rgba(255,255,255,1) 20%,rgba(255,255,255,1) 38%,rgba(255,255,255,0) 100%); /* ie10+ */ background: linear-gradient(left,  rgba(255,255,255,1) 0%,rgba(255,255,255,1) 20%,rgba(255,255,255,1) 38%,rgba(255,255,255,0) 100%); /* w3c */ filter: progid:dximagetransform.microsoft.gradient( startcolorstr='#ffffff', endcolorstr='#00ffffff',gradienttype=1 ); /* ie6-8 */ 

of course, didn't write above.. generated of ultimate css gradient..

  1. change preset (i used top right last one)
  2. change orientation horizontal
  3. change transparency level (below slider show how far want transparent)
  4. copy css , paste in fiddle (i had time test in ff 12 , works well)

good luck! let me know if need help.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -