2

嘿伙计们,我正在使用插件滚动到顶部,在我的网站正文上,我正在使用 mCustomScrollbar 插件。

问题是scrollbar插件的高度应该是这样的

html {
    height: 100%;
}

body {
    height: 100%;
    margin: 0;
    padding: 0 0px;
    color: #eee;
    background: #222;
    font-size: 13px;
}

高度应设置为 100%。

然后使用滚动到顶部我使用此功能

function goToTop() {
    $('body,html').animate({
        scrollTop: 0
    }, 1200);
}

滚动到顶部 jquery 是

// Define the variables
var easing, e, pos;

$(function(){

// Get the click event
$(".go-top-sets li").on("click", function(){

// Get the class
easing= $(this).attr("class");

// Get the scroll pos
pos= $(window).scrollTop();

// Set the body top margin
$("body").css({
  "margin-top": -pos+"px",
  "overflow-y": "scroll", // This property is posed for fix the blink of the window width change 
});

// Make the scroll handle on the position 0
$(window).scrollTop(0);

// Get the easing
switch(easing){
  case "easing-1":
    e= "cubic-bezier(0.600, 0.040, 0.980, 0.335)";
    break;
  case "easing-2":
    e= "cubic-bezier(1.000, -0.560, 0.000, 1.455)";
    break;
  case "easing-3":
    e= "cubic-bezier(0.175, 0.885, 0.320, 1.275)";
    break;
}

// Add the transition property to the body element
$("#ponyBody").css("transition", "all 1s " + e);

// Apply the scroll effects
$("#ponyBody").css("margin-top", "0");

// Wait until the transition end
$("#ponyBody").on("webkitTransitionEnd transitionend msTransitionEnd oTransitionEnd", function () {
  // Remove the transition property
    $("#ponyBody").css("transition", "none");
});
});

});

当我删除 100% 的高度时,滚动到顶部工作正常,但滚动条非常小且内容丰富。请帮忙。 谢谢

4

0 回答 0