【发布时间】:2015-04-17 09:13:32
【问题描述】:
我正在尝试通过 jQuery 使用 .queue() 功能对一些更改进行排队。我可以看到“背景黄色”和“边框变成橙色”,但我没有看到段落的移动!请帮助为什么它没有向左移动 250 像素! (我根据 cmets 为“段落”添加了“位置:相对”)
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$('#but1').click(function() {
$('p').queue(function() {
$(this).css('background','yellow');
$(this).css('border', '3px solid orange');
$(this).animate({ left: '250px' });
});
});
});
</script>
</head>
<body>
<button id=but1>Click Me! </button>
<p id=para1 style="position:relative;">This is a paragraph.</p>
</body>
</html>
后来,我尝试了这个脚本;仍然不起作用,现在我看不到段落中更早的 2 处更改,即“背景:黄色”和“边框:橙色”。
<script>
$(document).ready(function(){
$('#but1').click(function(){
$('p')
.queue('alpha',function(){
$(this).css('background','yellow');
})
.queue('alpha',function(){
$(this).css('border','3px solid orange');
})
.queue('alpha',function(){
$(this).animate({left:'250px'},1500});
})
.dequeue('alpha');
});
});
</script>
【问题讨论】:
-
left: 250px;.. 应该是left: '250px' -
你读过docs关于
.queue()的这种用法吗? -
是的,摄政王;一个更好的运行示例将不胜感激。
标签: jquery queue jquery-queue