jQuery:在页面加载后的一秒钟内显示字符串的右侧部分
我想在页面的第一秒钟显示字符串的一部分,在第二秒钟(1000毫秒)显示整个字符串 例1: 已加载的页面:jQuery:在页面加载后的一秒钟内显示字符串的右侧部分,jquery,html,css,string,fadeout,Jquery,Html,Css,String,Fadeout,我想在页面的第一秒钟显示字符串的一部分,在第二秒钟(1000毫秒)显示整个字符串 例1: 已加载的页面: 2+2 一秒钟之内: 2+2=4 (=4 added, 2+2 is not moved) 14+10=24 (=24 added, 14+10 is not moved) 例2: 14+10 一秒钟之内: 2+2=4 (=4 added, 2+2 is not moved) 14+10=24 (=24 added, 14+10 is not moved) 我更喜欢jQuery解决
2+2
一秒钟之内:
2+2=4 (=4 added, 2+2 is not moved)
14+10=24 (=24 added, 14+10 is not moved)
例2:
14+10
一秒钟之内:
2+2=4 (=4 added, 2+2 is not moved)
14+10=24 (=24 added, 14+10 is not moved)
我更喜欢jQuery解决方案,但我想知道是否可以对任何字符串执行此操作,以便:
1) 字符串可以有不同的长度,数学公式“=”是一种分隔符。(“=”是刚加载页面时未显示的字符串右侧的第一部分)
2) 字符串不包含有助于操纵字符串右侧部分可见性/淡出效果的附加或任何其他html标记。html:
<div id="container"></div>
var firstPart = "2+2",
secondPart = "=4";
$("#container").append(firstPart);
setTimeout(function(){
$("#container").append(secondPart);
}, 1000);
小提琴:
<div id="container"></div>
var firstPart = "2+2",
secondPart = "=4";
$("#container").append(firstPart);
setTimeout(function(){
$("#container").append(secondPart);
}, 1000);
有很多方法可以做到这一点,这里有一个:
<p class="foo">2 + 2</p>
<script>
window.setTimeout(function(){
var result = eval($('.foo').html());
$('.foo').append(' = ' + result);
}, 1000);
</script>
2+2
setTimeout(函数(){
var result=eval($('.foo').html());
$('.foo').append('='+结果);
}, 1000);
您可以使用JavaScript方法获取=
字符前面的所有内容,然后在1秒后使用替换为完整字符串,如下所示:
// The Equation String
var s = '2 + 2 = 4';
// Split the String at the `=` Character
var splitString = s.split('=');
// Add the First Part of the String to the `div`
$('#answer').text(splitString[0]);
// Wait 1 Second and Show the Whole String
setTimeout(function(){
$('#answer').text(s);
}, 1000);
这将适用于任何以=
字符作为分隔符的字符串表达式
这是一本书
我希望这有帮助 这可能对您有所帮助 html:
这里是我意识到你说你可以使用jQuery,但只是为了好玩,我决定把一些纯javascript的东西放在一起。我在以下JSFIDLE中完成了此操作:。这里的关键是使用css类来显示和隐藏元素(如下所示):
为了在脚本中添加漂亮的淡入淡出/显示动画,您需要使用css动画()。无论如何,我希望你觉得这个答案有趣 你试过自己解决这个问题吗?你采取了什么方法,为什么不起作用?那么这些数字会被设置为整数吗<代码>变量编号=2+2代码>还是字符串<代码>变量编号='2+2'代码>我有点困惑。我完全支持纯JavaScript,但为什么op说他们更喜欢jQuery解决方案?为了好玩,让它慢一点!当然,纯JS也可以。谢谢你的帮助……在我之前的发言中有一点讽刺:)