- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望在这里使用 jScrollPane 的“scrollToElement”API 函数:
http://dextersgospel.com/index-test.html
可以在此处找到有关其使用说明:
http://jscrollpane.kelvinluck.com/api.html#scrollTo
我遇到的问题是“stickToTop”参数。单击箭头时,我希望它将目标 div 带到视口(viewport)的顶部(而不仅仅是像当前那样几乎不可见)。 “stickToTop”参数应该可以处理这个问题,但我无法让它工作。
我尝试按如下方式实现这一点,但没有成功:
api.scrollToElement(target_div_id, {stickToTop: true});
我已经尝试过:
api.scrollToElement(target_div_id, true);
这是我当前的完整代码:
$(function()
{
/* INITIALIZES jScrollPane on ENTIRE BROWSER WINDOW */
var win = $(window);
var isResizing = false;
var container = $('#full-page-container');
win.bind(
'resize',
function()
{
if (!isResizing) {
isResizing = true;
// Temporarily make the container tiny so it doesn't influence the
// calculation of the size of the document
container.css(
{
'width': 1,
'height': 1
}
);
// Now make it the size of the window...
container.css(
{
'width': win.width(),
'height': win.height()
}
);
isResizing = false;
container.jScrollPane(
{
'showArrows': false,
'mouseWheelSpeed': 75,
'contentWidth': 960, //So content doesn't jump around
'animateScroll': true,
'animateDuration': 600,
'hijackInternalLinks': true //HAD TO HAVE THIS FOR ANCHORS TO WORK!
}
);
}
}
).trigger('resize');
//Awesome scrollToY function for our duct tape arrows - no flicker + built w/jScrollPane
var api = container.data('jsp');
$('.proposal').bind(
'click',
function()
{
var target_div_id = '#' + $(this).attr("title"); // gives you the TITLE of the clicked link
api.scrollToElement(target_div_id, true);
return false;
}
);
});
任何关于如何让 jScrollPane 的“stickToTop”参数适用于“scrollToElement”方法的帮助将非常感激!
最佳答案
您的代码总体工作正常,stickToTop
选项似乎不起作用的原因是proposal-X div的css。
stickToTop
会滚动这些 div,使它们位于页面顶部,但要确定它们的上边缘,它使用 margin-top和 padding-top 值。因此,滚动后,它显示为 *target_div_id* div 的顶部边缘不在页面顶部(这不是真的)。是的,只有 jScrollpane 考虑了 margin 和 padding 的值。
这个问题的解决方案很简单,将proposal-X div包装在另一个div中(假设使用类.proposal-wrapper。然后移动CSS从提案 div 到 .proposal-wrapper 类的定义的 margin-top 和 padding-top 定义。
关于jQuery jScrollpane 的scrollToElement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7316027/
我想创建一个网页,它可以在没有任何用户交互的情况下从一个元素连续循环滚动到下一个元素。我已经搜索过,看起来 scrollToElement 就是我要找的东西(实际上 this answer on an
您好,我正在使用 Jquery scrollToElement 滚动到页面上的特定 div(它是单个页面布局),但现在有一个新页面。我想知道如何使用相同的导航返回到旧页面并滚动到特定的 div 我使用
更新:我能够让我的滚动条按预期工作,但我觉得我已经解决了实际问题,如果有人有更可靠的答案,我会很高兴,我已经更新并在我正在使用的新 jQuery 下面的代码片段中注明. 我正在为 iPad/Andro
我刚开始在 Xcode 7 (7.0.1) 中使用 Swift 进行一些 UI 测试,并且有一个想法要解决以继续测试。 我的应用程序有一个包含很多单元格的表格 View ,我想点击一个不可见的单元格;
我是一名优秀的程序员,十分优秀!