我是新手,我怎么能添加到我的代码scrollTop margin + 100px? 在页面上有一些从顶部的边缘,但我找不到他。我无法理解在javascript文件中键入margin-top的位置。
/*************
* = Parallax *
*************/
jQuery(document).ready(function ($) {
//Cache some variables
var links = $('.nav').find('li');
slide = $('.slide');
button = $('.button');
mywindow = $(window);
htmlbody = $('html,body');
//Create a function that will be passed a slide number and then will scroll to that slide using jquerys animate. The Jquery
//easing plugin is also used, so we passed in the easing method of 'easeInOutQuint' which is available throught the plugin.
function goToByScroll(dataslide) {
var offset_top = ( dataslide == 1 ) ? '0px' : $('.slide[data-slide="' + dataslide + '"]').offset().top;
htmlbody.stop(false, false).animate({
scrollTop: offset_top
}, 1500, 'easeInOutQuart');
}
//When the user clicks on the navigation links, get the data-slide attribute value of the link and pass that variable to the goToByScroll function
links.click(function (e) {
e.preventDefault();
dataslide = $(this).attr('data-slide');
goToByScroll(dataslide);
$(".nav-collapse").collapse('hide');
});
//When the user clicks on the navigation links, get the data-slide attribute value of the link and pass that variable to the goToByScroll function
$('.navigation-slide').click(function (e) {
e.preventDefault();
dataslide = $(this).attr('data-slide');
goToByScroll(dataslide);
$(".nav-collapse").collapse('hide');
});
});
答案 0 :(得分:0)
将此内容放入点击事件中,以“滚动到顶部”按钮/链接/其他..
$("body").scrollTop( 100);