Google Translate dynamic text demo
HTML
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<title>Google Translate Test</title>
</head>
<body>
<div class="popup" onclick="myFunctiona()">Click me!
<span class="popuptext" id="myPopup">Popup text...</span>
</div>
<div class="destination">
<p>This is some text already on the page that could be translated by the Google Translate Web Element. <a href="#" class="loadMore">Load More</a></p>
</div>
<div id="google_translate_element"></div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({ pageLanguage: "en" }, "google_translate_element");
};
$(function () {
$(".loadmore").click(function () {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
$("<p/>", {
text: "This is some injected text that will not be translated."
}).appendTo($(".popuptext"));
});
$.getScript("//translate.google.com/translate_a/element.js?cb=googleTranslateElementInit");
});
</script>
</body>
</html>
CSS
/* Popup container */
.popup {
position: relative;
display: inline-block;
cursor: pointer;
}
/* The actual popup (appears on top) */
.popup .popuptext {
visibility: hidden;
width: 160px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 8px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -80px;
}
/* Popup arrow */
.popup .popuptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
/* Toggle this class when clicking on the popup container (hide and show the popup) */
.popup .show {
visibility: visible;
-webkit-animation: fadeIn 1s;
animation: fadeIn 1s
}
/* Add animation (fade in the popup) */
@-webkit-keyframes fadeIn {
from {opacity: 0;}
to {opacity: 1;}
}
@keyframes fadeIn {
from {opacity: 0;}
to {opacity:1 ;}
}
JavaScript
function myFunction() {
var popup = document.getElementById("myPopup");
popup.classList.toggle("show");
}