锚标记,用于使用jQuery转到div类的开头 [英] Anchor tag, to go to the beginning of a div class w/ USING jQuery

查看:107
本文介绍了锚标记,用于使用jQuery转到div类的开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我希望包含一个指向网页主要部分的链接,通过输入到我的标题全局链接.inc文件。



当您选择链接时,它会滚动到页面的主要部分,它位于div class content-body

$内b
$ b

 < div class =content-body> 
主要内容
< / div>

所以它会向下滚动到div的开始位置。



我想实现锚标记功能,但它转到div类,而不是id。



我想知道是否有办法用jQuery做到这一点。为什么我想要这样做,是因为我可以在整个现有网站中全局实现这一功能。 解决方案

这可能对您有所帮助。

您可以创建一个小函数来实现此行为。真是有用。你完全避免打开窗户或模式,以及类似的东西。

 函数to_position(divid){
$('html,body')。animate({scrollTop:$( divid).position()。top - 50},'slow');
}

所以。

  to_position('#my_id')
//或类,或者任何jquery选择
to_position('。my_class')
//
to_position('input [name =lorenzolamas]')


I want to implement a global anchor type of functionality.

I want to include a link to the main part of the web page, globally by inputting into my header.inc file.

When you select the link, it will scroll to the main part of the page, which is within the div class content-body

<div class="content-body">
  main content
</div>

So it will scroll down to where the div begins.

I want to achieve the anchor tag functionality, but it goes to a div class, not id.

I want to know if there is a way to do this with jQuery. Why I want to do this, is because I can globally implement this throughout the entire existing website.

解决方案

This may help you.

You can create a small function to make this behavior. Is realy usefull. You cant totally avoid open windows or modals, and things like that.

 function to_position(divid){
     $('html, body').animate({scrollTop:$(divid).position().top - 50 }, 'slow');
 }

So. you use the function like this.

 to_position('#my_id')
 //or class, or whatever jquery selector
 to_position('.my_class')
 //
 to_position('input[name="lorenzolamas"]')

这篇关于锚标记,用于使用jQuery转到div类的开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆