【发布时间】:2021-01-28 17:12:57
【问题描述】:
我已阅读此答案 Modifying element from google.translate.TranslateElement results 以及其他处理修改样式和加载 Google 翻译翻译元素的内容。
与我的用法不同的是,我使用的是layout: google.translate.TranslateElement.InlineLayout.VERTICAL,而不是SIMPLE;所有其他答案都涉及SIMPLE。
我遇到的一个问题是在 google-translate div 上使用 .fadeIn 不起作用。我仍然收到来自.goog-logo-link 的文字闪现,我看到Select a Language 在它变为Translate 之前。
这可能与 Modifying element from google.translate.TranslateElement results 中的 myTimer 函数有关。但是myTimer 是我想出如何将.goog-te-combo option:first 的文本从Select a Language 更改为Translate 的唯一方法。
所以,
-
有没有更有效的方法将
.goog-te-combo option:first的文本从Select a Language更改为Translate? -
如何让
.fadeIn处理google-translatediv,以便将文本从Select a Language更改为Translate并隐藏.goog-logo-link,直到整个div 淡入?
jsfiddle:https://jsfiddle.net/gfzcjwmv/7/
<script>
$(window).on('load', function() {
$(".goog-logo-link").empty();
$('.goog-te-gadget').html($('.goog-te-gadget').children());
$("#google-translate").fadeIn('1000');
});
</script>
<div id="google-translate">
<div id="google_translate_element"></div>
<script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en', includedLanguages: 'af,ach,ak,am,ar,az,be,bem,bg,bh,bn,br',
layout: google.translate.TranslateElement.InlineLayout.VERTICAL
}, 'google_translate_element');
}
</script>
<script type="text/javascript" src="https://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</div>
<script>
$(window).on('load', function() {
function cleartimer() {
setTimeout(function(){
window.clearInterval(myVar);
}, 1000);
}
function myTimer() {
if ($('.goog-te-combo option:first').length) {
$('.goog-te-combo option:first').html('Translate');
cleartimer();
}
}
var myVar = setInterval(function(){ myTimer() }, 300);
});
</script>
【问题讨论】:
标签: javascript jquery google-translate