在C#中计算MVC应用查看页面的百分比可以通过以下步骤实现:
currentScrollPosition
表示当前滚动位置,totalPageHeight
表示页面的总高度。在C#中实现MVC应用查看页面的百分比计算,可以使用以下代码示例:
// Controller
public class PageViewController : Controller
{
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult CalculatePercentage(int currentScrollPosition, int totalPageHeight)
{
double percentage = (double)currentScrollPosition / totalPageHeight * 100;
return Json(new { percentage });
}
}
// View (Razor syntax)
<script>
$(window).scroll(function () {
var currentScrollPosition = $(window).scrollTop();
var totalPageHeight = $(document).height();
$.ajax({
url: '@Url.Action("CalculatePercentage", "PageView")',
type: 'POST',
data: { currentScrollPosition: currentScrollPosition, totalPageHeight: totalPageHeight },
success: function (data) {
var percentage = data.percentage;
// Do something with the percentage value
}
});
});
</script>
这样,当用户滚动页面时,会通过Ajax请求将当前滚动位置和页面总高度发送到后端进行计算,并将计算得到的百分比返回给前端进行处理。
Hello Serverless 来了
GAME-TECH
云+社区技术沙龙[第19期]
第四期Techo TVP开发者峰会
云+社区技术沙龙 [第31期]
DBTalk
发现教育+科技新范式
腾讯技术开放日
云+社区技术沙龙 [第32期]
云+未来峰会
领取专属 10元无门槛券
手把手带您无忧上云