jQuery 自定义加载不流畅(相反,原始内容出现,然后被修改)
我正在使用 Squarespace CMS 系统开发一个网站,并添加了一些简单的 jQuery 来删除过滤内容时出现的一些自动添加的文本(特别是“条目”文本)。
在我将 Google 翻译脚本添加到页脚之前,一切顺利,没有任何问题。现在,“Entries in”文本的删除并不顺利——“Entries in”文本在页面加载时首先显示,然后被删除,因此感觉有点跳跃。页脚中的 Google 翻译脚本似乎造成了干扰,我担心它可能会干扰我随着项目的进展可能添加到网站的任何其他 jQuery。我很好奇我可以做些什么来确保这些自定义项顺利加载?
我正在开发的网站(正在进行中)可以在 wohf.squarespace.com 上查看,
到目前为止我拥有的代码如下:
<script src="/storage/Scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
<!--
$(function(){
//***************************************
// Remove "Entries In" text
//***************************************
$('.journal-filter-header h2:contains(Entries in)').each(function(){
var str = $(this).html();
$(this).html(str.replace('Entries in',''));
});
});
-->
</script>
... 以及页脚中的 Google 翻译:
<div id="footerRight">
<div id="google_translate_element"></div>
<script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en'
}, 'google_translate_element');
}
</script>
<script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</div>
同样,任何帮助都是非常感谢!
I am working on a site using the Squarespace CMS system, and have added some simple jQuery to remove some automatically added text that comes up when filtering content (specifically "Entries in" text).
This worked smoothly without any problem until I added Google Translate script into the footer. Now the removal of the "Entries in" text is not smooth -- the "Entries in" text shows up first when the page is loaded and then gets removed, so the it feels a bit jumpy. It seems like the Google Translate script in the footer is causing the interference and I'm worried that it could interfere with any additional jQuery I might add to the site as the project progresses. I'm curious what I can do better to make sure these sorts of customizations load smoothly?
The site I'm working on (in progress) can be viewed at wohf.squarespace.com
the code I have so far is the following in the :
<script src="/storage/Scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
<!--
$(function(){
//***************************************
// Remove "Entries In" text
//***************************************
$('.journal-filter-header h2:contains(Entries in)').each(function(){
var str = $(this).html();
$(this).html(str.replace('Entries in',''));
});
});
-->
</script>
... and the following for Google Translate in the footer:
<div id="footerRight">
<div id="google_translate_element"></div>
<script>
function googleTranslateElementInit() {
new google.translate.TranslateElement({
pageLanguage: 'en'
}, 'google_translate_element');
}
</script>
<script src="http://translate.google.com/translate_a/element.js?cb=googleTranslateElementInit"></script>
</div>
Again, any help is greatly appreciated!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您确实应该尝试找出如何在 CMS(服务器端)中更改此设置。 JavaScript 仅旨在帮助您处理动态内容,而不是静态内容。
You really should try to work out how to change this in your CMS (server side). JavaScript is only intended to help you with dynamic content, not static content.
您可以尝试直接在页面末尾的脚本标记中运行修复函数,而不是在 jQuery“就绪”上下文中。换句话说,让您的代码在页面加载完成之前运行。 (当然,这可能完全有帮助,也可能不完全有帮助。)
You could try running your fix-up function directly in a script tag towards the end of the page, and not in a jQuery "ready" context. In other words, have your code run before the page load completes. (This may or may not completely help, of course.)
您尝试过 jQuery.getScript() 吗?您应该能够延迟加载翻译脚本,直到“替换”完成。
http://api.jquery.com/jQuery.getScript/
Have you tried jQuery.getScript() ? You should be able to delay loading the translate script until your 'replace' is done.
http://api.jquery.com/jQuery.getScript/