Javascript 使用按钮为滚动位置添加书签,该按钮在单击时滚动到该位置

Javascript 使用按钮为滚动位置添加书签,该按钮在单击时滚动到该位置,javascript,jquery,css,Javascript,Jquery,Css,我有一些JavaScript使用进度条显示滚动进度。这样我就有了一个书签按钮,可以在当前进度位置添加一个图标/按钮。我想做的是使用cookie添加以保存该位置,另外添加一个指向按钮的链接,该按钮将滚动到视口中的书签位置 所以我现在的代码是 // the elements indicating scroll progress for document height (function(){ var w = $(window); var prog = $('.progress-bar'); var

我有一些JavaScript使用进度条显示滚动进度。这样我就有了一个书签按钮,可以在当前进度位置添加一个图标/按钮。我想做的是使用cookie添加以保存该位置,另外添加一个指向按钮的链接,该按钮将滚动到视口中的书签位置

所以我现在的代码是

// the elements indicating scroll progress for document height
(function(){
var w = $(window);
var prog = $('.progress-bar');
var progCount = $('.progress-count');

var wh, h, sHeight;

//the containing div from which the height is calculated
function setSizes() {
    wh = w.height();
    h = $('#page-content-wrapper').height();
    sHeight = h - wh;
}

setSizes();

w.on('scroll', function () {
    var perc = Math.max(0, Math.min(1, w.scrollTop() / sHeight));
    updateProgress(perc);
})

.on('resize', function () {
    setSizes();
    w.trigger('scroll');
});

//progress percentage 
function updateProgress(perc) {
    progCount.html(Math.round(perc * 100) + "%");
    prog.css({width : perc*100 + '%'});
    console.log (perc*100 + '%');
}

//bookmark function that adds an icon/button at the end of the progress bar's current position
//within the add - I have tried using jquery scrollto to get the 'perc' value as a scrollto directive
$('#bookmark').on("click", function() {
    var add = "";
    l = prog.width() - 2;
    t = 59;
    add = "<a href='#' title='$(...).scrollTo( 0, perc, {queue:true} );'><div class=\"star\" style=\" left:";
    add += l;
    add += "px; top:";
    add += t;
    add += "px;\"><span class='icon-bookmark tooltipper' data-toggle='tooltip' data-placement='bottom' title data-original-title='Go Bookmark'></span></a></div>";
    $('.progress-bar').append(add);

});
})

我希望这能恰当地解释我所追求的


谢谢大家!

看起来不错,但你的问题到底是什么?或者你可以用一个部分,然后书签…什么。问题是,当我向下滚动并将该位置标记为书签时,假设它是50%,我希望我附加的按钮或书签有一个向下滚动到50%的链接。@JCOC611-我已经有了部分滚动到设置,我需要的是在用户指定的点上动态设置书签,这些点在添加书签时位于文档高度的x%。