gpt4 book ai didi

javascript - ASP .NET MVC 5 在 View.cshtml 文件中编写 javascript

转载 作者:行者123 更新时间:2023-11-30 07:08:03 24 4
gpt4 key购买 nike

<分区>

我是 ASP .NET 的新手,我正在努力使用 MVC 中的 javascript。我在 View 文件夹中有一个 IndexView.cshtml 文件,我想在里面写一个简短的 javascript 部分,用一个按钮将网站移回顶部。它在普通 html 中完美运行,所以就是这样。通常,每当我从网站顶部向下滚动时,一个按钮就会出现,而当我返回到最顶部时,该按钮就会消失。在这里它根本没有出现。我该怎么做才能让它发挥作用?提前致谢!

所以这是在 IndexView.cshtml 中我正文的末尾 </body> 之前标签。

<script type="text/javascript">
$(document).ready(function() {
$().UItoTop({ easingType: 'easeOutQuart' });

});
</script>
<a href="#" id="toTop"><span id="toTopHover"> </span></a>

这是脚本文件夹/Scripts/move-top.js 中 move-top.js 的一部分

(function ($) {
$.fn.UItoTop = function (options) {
var defaults = {
text: 'To Top', min: 200, inDelay: 600, outDelay: 400, containerID: 'toTop', containerHoverID: 'toTopHover',
scrollSpeed: 1200, easingType: 'linear'
}, settings = $.extend(defaults, options), containerIDhash = '#' + settings.containerID, containerHoverIDHash = '#' + settings.containerHoverID;
$('body').append('<a href="#" id="' + settings.containerID + '">' + settings.text + '</a>');
$(containerIDhash).hide().on('click.UItoTop', function ()
{
$('html, body').animate({ scrollTop: 0 }, settings.scrollSpeed, settings.easingType);
$('#' + settings.containerHoverID, this).stop().animate({ 'opacity': 0 }, settings.inDelay, settings.easingType); return false;
}).prepend('<span id="' + settings.containerHoverID + '"></span>').hover(function ()
{ $(containerHoverIDHash, this).stop().animate({ 'opacity': 1 }, 600, 'linear'); }, function ()
{ $(containerHoverIDHash, this).stop().animate({ 'opacity': 0 }, 700, 'linear'); });
$(window).scroll(function () {
var sd = $(window).scrollTop();
if (typeof document.body.style.maxHeight === "undefined")
{
$(containerIDhash).css({
'position': 'absolute', 'top': sd + $(window).height() - 50
});
}
if(sd>settings.min)
$(containerIDhash).fadeIn(settings.inDelay);else
$(containerIDhash).fadeOut(settings.Outdelay);});};})(jQuery);

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