我找到了一个可用的 jQuery,可以随着时间的推移动态更改文本,并具有淡入淡出效果。 我希望从外部链接自动添加这些词:Words Page .
我该怎么做?
我的目标是保持 JS 文件小/最小,因为我有更多其他 jQuery 代码。
感谢任何指导!
检查我的:enter link description here
HTML
<span class="textbox">Stylish</span>
CSS
span.textbox{
display: inline;
float: left;
font-size: 20px;
margin-top: 50px;
margin-left: 50px;
color: #131313;
font-weight: bold;
letter-spacing: 1px;
}
JS
$(document).ready(function() {
// List your words here:
var words = [
'Awesome',
'Special',
'Sofisticated',
'Simple',
'Great',
'Better',
'Stronger',
'Stylish',
'Flawless',
'Envied',
'Strong',
'Sucessful',
'Grow',
'Innovate',
'Global',
'Knowledgable',
'Solid'
], i = 0;
setInterval(function(){
$('.textbox').fadeOut(500, function(){
$(this).html(words[i=(i+1)%words.length]).fadeIn(500);
});
}, 5000);
});
最佳答案
使用 jQuery.ajax()
$.ajax('http://www-958.ibm.com/software/data/cognos/manyeyes/datasets/5-adjectives-to-describe-company-2/versions/1.txt').done(function(response, status) {
// Check for error result (404, 500, etc)
if (status !== 'error')
{
// Split words using ", " as separator to words array.
var words = response.split(", ");
// Your code here to change texts. Nothing changed.
setInterval(function(){
$('.textbox').fadeOut(500, function(){
$(this).html(words[i=(i+1)%words.length]).fadeIn(500);
});
}, 5000);
}
});
但是由于跨域错误,您将无法获取该网址。
将文本复制到您的域或进行重定向。
关于javascript - 从外部链接每 5 秒更改一次文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22722011/