我正在尝试淡入一个div,让它在屏幕上停留几秒钟,然后淡出。问题是它没有像我预期的那样在屏幕上停留很长时间,即使设置了大约10秒的延迟,它也只是短暂地停留在屏幕上。我读了很多帖子,尝试了很多东西,比如settimeout,但是我什么也没做。
下面是我的脚本:
<script type="text/javascript">
function pageLoad() {
$("[id*=lnkSelect]").live("click", function () {
var price = $("#price").html($(".prodprice", $(this).closest('tr').prev().children ('td.prodpricelabel')).html());
var code = $("#code").html($(".prodcode", $(this).closest('tr').prev().prev().children ('td.prodcodelabel')).html());
//Build the new HTML
$(code).prepend("<br/>Item: ");
$(code).append("<br/>Has been<br/>added to your cart.<br/>Price: ");
$(".tooltipleft").html(code); //Set the new HTML
$(".tooltipleft").append(price);
$(".tooltipleft").fadeIn('slow').delay(5000).fadeOut('slow');
});
};
</script>因此,我从html中获取产品代码和价格,修改div中的html,然后将其淡入,作为商品已添加到购物车的通知。
这是我想要淡入的div:
<div class="tooltipleft" id="tooltip">
<span id="code"></span><span id="price"></span>
</div>和网格中的按钮:
<asp:ImageButton ID="lnkSelect" runat="server" ImageUrl="~/Buttons/add_to_cart.png"
AlternateText="Add To Cart" CommandArgument='<%# Eval("ProductID") %>' CommandName="Add"
ImageAlign="Right" />发布于 2013-01-13 22:47:25
这样做:http://jsfiddle.net/LJsNG/1/
$(function () {
$('.tooltipleft').fadeIn('slow', function () {
$(this).delay(5000).fadeOut('slow');
});
});发布于 2013-01-13 22:41:21
使用show和hide而不是fadeIn和fadeOut来查看它是否工作。如果它不起作用,那么你的问题出在别的地方。正如您看到的工作example一样,$('#foo').fadeIn().delay(2000).fadeOut();是正确的代码行。
$('#tooltipleft').show(0).delay(5000).hide(0);https://stackoverflow.com/questions/14304473
复制相似问题