Tag: 锚点

jQuery滚动到锚点(减去设定的像素数量)

我使用以下代码使用jQuery滚动到锚点: $(document).ready(function() { function filterPath(string) { return string .replace(/^\//,”) .replace(/(index|default).[a-zA-Z]{3,4}$/,”) .replace(/\/$/,”); } var locationPath = filterPath(location.pathname); var scrollElem = scrollableElement(‘html’, ‘body’); $(‘a[href*=#]’).each(function() { var thisPath = filterPath(this.pathname) || locationPath; if ( locationPath == thisPath && (location.hostname == this.hostname || !this.hostname) && this.hash.replace(/#/,”) ) { var $target = $(this.hash), target = this.hash; if (target) { var […]

jQuery:在调用URL时滚动到锚点,替换浏览器行为

我已经知道了jQuery插件ScrollTo,但到目前为止我还没有找到任何方法来实现以下内容: 用户访问我的网站(通过键入,而不是通过单击我页面上的链接)domain.com/bla.php#foo 并且锚“#foo”存在。 现在我希望用户的浏览器不会自动滚动到“#foo”,而是我想要平滑滚动,以便元素’#foo’位于视图的中间而不是在绝对的顶部位置用户查看。 谢谢到目前为止!

打开带有锚链接的选项卡

我有一些典型的标签内容,我真的需要一些帮助。 我想实现,当用户尝试通过外部锚链接( http://www.url.com#content2 )到达特定选项卡时,导航链接将被激活并显示正确的选项卡。 谢谢您的帮助。 HTML Inner nav navigation link1 Inner nav navigation link2 Inner nav navigation link3 content1 goes here content2 goes here content3 goes here JAVASCRIPT $(document).ready(function () { $(“.tab-content”).hide(); $(“.tab-content:first”).show(); $(“.inner-nav li:first”).addClass(“active”); $(“.inner-nav a”).click(function(){ $(“.inner-nav li”).removeClass(“active”); $(this).parent().addClass(“active”); var currentTab = $(this).attr(“href”); $(“.tab-content”).hide(); $(currentTab).show(); return false; }); }); 我在这里有一个实例。所以,如果你点击导航,一切正常,但如果你想去一个特定的标签kajag.com/themes/book_your_travel/location.html#sports_and_nature,正确的标签不会打开。