如何滚动到jQuery中的元素? [英] How to scroll to an element in jQuery?

查看:135
本文介绍了如何滚动到jQuery中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JavaScript中完成了以下代码,将焦点放在特定的元素(branch1是一个元素)上,

  document .location.href = #BRANCH1; 

但是,因为我也在我的web应用程序中使用jQuery,所以我想要在上面的代码jQuery的。我曾尝试过,但不知道为什么它不工作,

  $(#branch1)。 

上面的jquery(focus())代码不能用于div,而如果我正在尝试同样的代码与文本框,然后它的工作,

请告诉我,我怎么能把重点放在一个div元素使用jQuery?



谢谢!

解决方案

检查 jQuery.ScrollTo ,我认为这是你想要的行为,检查演示


I have done the following code in JavaScript to put focus on the particular element (branch1 is a element),

document.location.href="#branch1";

But as I am also using jQuery in my web app, so I want to do the above code in jQuery. I have tried but don't know why its not working,

$("#branch1").focus();

The above jquery (focus()) code is not working for div, whereas If i am trying the same code with textbox, then its working,

Please tell me, how can I put focus on a div elemnt using jQuery?

Thanks!

解决方案

Check jQuery.ScrollTo, I think that's the behavior that you want, check the demo.

这篇关于如何滚动到jQuery中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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