gpt4 book ai didi

javascript - (window).scrollTop 函数在第一次单击时不会触发

转载 作者:行者123 更新时间:2023-11-28 07:56:10 25 4
gpt4 key购买 nike

我有一个可点击的条形图,当点击它时,它会触发 mainQuestBarClick 函数。在此函数中,我使用此行 $(window).scrollTop($('#scrollHere').offset().top); 滚动到scrollHere div。当我单击该栏时,它不会滚动到那里,但第二次单击它时,它会滚动。可能是什么原因?

这是函数:

var mainQuestBarClick = function (event, pos, obj) {
if (!obj)
return;
$(window).scrollTop($('#scrollHere').offset().top);
//goToByScroll($("#scrollHere").attr("id"));

var selectedBranchName = encodeURIComponent(obj.series.label);
$("#SelectedBranchFromBarChart").val(selectedBranchName);

$("#content").block();

//Stats Chart
$.ajax({
type: "GET",
url: '@Url.Action("GetStatsForSpecificBranch", "SurveyReports")',
data: "BranchName="+encodeURIComponent(obj.series.label)+"&SurveyId=" + $("#SurveyId").val() + "&startDate=" + $("#ReportStartDate").val() + "&endDate=" + $("#ReportEndDate").val(),
cache: false,
success: function (r) {
if (r.success == false) {
noty({ text: r.resultText, type: 'error', timeout: 2000, modal: true });
} else {


$("#statboxSurveyCountTitle").html("<b>" + selectedBranchName + "</b> Şubesi Anket Sayısı");
$("#statboxSurveyAvgTitle").html("<b>" + selectedBranchName + "</b> Şubesi Anket Ortalaması");
$("#statboxSurveyRecommTitle").html("<b>" + selectedBranchName + "</b> Şubesi Tavsiye Oranı")
$("#StatboxesDiv").show();
$("#SurveyCountVal").text(r.FilledSurveyCount);
$("#SurveyAvgVal").text(r.FilledSurveyAverageRating.toFixed(2));
$("#SurveyRecommVal").text("%"+r.RecommendYesPercent);
}
},
error: function (error) {
noty({ text: "Bir hata oluştu lütfen tekrar deneyiniz!", type: 'error', timeout: 2000, modal: true });
}

});
$("#content").unblock();

}

最佳答案

这是这个问题的较晚的解决方案,但不知何故我设法做了我想做的事。这是我解决问题的方法:

我创建了一个函数,它获取要滚动的元素的 id:

function goToByScroll(id){
@{int scroll = 600;
if(Model.BranchList.Count <= 1)
{
scroll = 750;
}
}
// Scroll
$('html,body').animate({scrollTop:@scroll}, 1000);
}

并在上面的问题中更改了我的代码中的这部分:

$(window).scrollTop($('#scrollHere').offset().top);

对此:

goToByScroll($("#scrollHere").attr("id"));

关于javascript - (window).scrollTop 函数在第一次单击时不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26062166/

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