简体   繁体   English

localscroll的哈希选项,滚动时会闪烁页面。 如何使滚动平滑

[英]localscroll's hash option, flickers the page when scrolling. How can I make the scrolling smooth

I'm implementing a jquery plugin ( localscroll ) to smooth scroll to named anchor elements withing a page. 我正在实现一个jquery插件( localscroll )以平滑滚动到页面的命名锚元素。 localscroll supports an option called 'hash', what it basically does is it appends the named anchor hash into the URL making it easy for the user to bookmark and move using the browser back/forward buttons. localscroll支持一个名为“哈希”的选项,它的基本作用是将命名的锚哈希附加到URL中,从而使用户可以轻松使用浏览器的后退/前进按钮添加书签和移动。


HTML

<ul id="navigation" class="main_menu">
    <li><a href="#panel_home">Home</a></li>
    <li><a href="#panel_story">Story</a></li>
    <li><a href="#panel_mantra">Mantra</a></li>
    <li><a href="#panel_showcase">Showcase</a></li>
    <li><a href="#panel_experience">Experience Us</a></li>
</ul>

Javascript (jquery)

$(document).ready(function () {
    $("#navigation").localScroll({
        offset: {left: 0, top: -56},
        hash: true,
        easing: 'easeInOutExpo'
     });
});

The above code runs fine, but whenever a link is clicked the scrolling starts with a flicker (probably because the default behavior of the browser is to jump to the named anchor). 上面的代码运行正常,但是每当单击链接时,滚动就会以闪烁开始(可能是因为浏览器的默认行为是跳转到指定的锚点)。 This flicker thing is more visible in Firefox than Chrome or Safari and is a big NO-NO. 在Firefox中,这种闪烁的东西比Chrome或Safari更为明显,这是一个很大的禁止。 How can I make the transition smooth with the address bar reflecting the current named anchor?? 如何使用地址栏反映当前命名锚点使过渡平滑? Any help is much appreciated. 任何帮助深表感谢。 Thanx! 谢谢!

I found out why my page was flickering upon clicking the links mapped with localscroll. 我发现了为什么单击与localscroll映射的链接后页面会闪烁。 I was including the jquery.js file after the localscroll.js file, which was causing this strange behavior. 我在localscroll.js文件之后包含了jquery.js文件,这导致了这种奇怪的行为。 So, I included all the minified versions of jquery, localscroll, easing and other javascripts that I was using in my scripts in a single .js file and this fixed the problem. 因此,我将在脚本中使用的所有缩小版本的jquery,localscroll,easing和其他javascript都包含在单个.js文件中,从而解决了该问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM