gpt4 book ai didi

jQuery:当 margin-top < 0 时停止滚动文本

转载 作者:行者123 更新时间:2023-12-01 03:45:18 26 4
gpt4 key购买 nike

我的滚动文本有 2 个按钮工作正常,但我似乎无法让它停止。我正在尝试使用 and if 语句在边距 < 0 时禁用该按钮。

请在此处查看演示:

http://jsbin.com/udumos/2/edit

代码:

$(function() {

var margin = parseInt(jQuery('#content').css('margin-top'), 10);

$('#scroll-down').click(function() {

$('#content').animate({
'margin-top': '+=50'
}, 1000);

return margin;

});

if (margin > 0) {
$('#scroll-up').click(function() {

$('#content').animate({
'margin-top': '-=50'
}, 1000);

});
}

});

最佳答案

您需要在每次点击事件时更新边距。

$(function () {
$('#scroll-down').click(function () {
$('#content').animate({
'margin-top': '+=50'
}, 1000);
return margin;
});

$('#scroll-up').click(function () {
var margin = parseInt(jQuery('#content').css('margin-top'), 10);
if (margin >= 0) {
$('#content').animate({
'margin-top': '-=50'
}, 1000);
}
});
});

关于jQuery:当 margin-top < 0 时停止滚动文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14164040/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com