简体   繁体   English

jQuery scrollTop效果不佳

[英]JQuery scrollTop doesn't work well

I am trying to scroll to a div with two classes class="media unread" 我正在尝试滚动到具有两个类class="media unread"的div

I've place this line inside application.js inside $(document).ready(function() { 我有这个地方线内application.js里面$(document).ready(function() {

$("html,body").animate({ scrollTop: $(".media.unread").offset().top - (window.innerHeight || document.documentElement.clientHeight) + $(".media.unread").height() + 15} , 800);

This works well in firefox, but on chrome I need to manually scroll a bit more down for it to reach the div and make it visible 这在firefox中效果很好,但是在chrome上,我需要手动向下滚动一点才能到达div并使其可见

Am I missing something? 我想念什么吗? Or my chrome is broken? 还是我的铬坏了?

Why don't you use $('.media.unread').offset().top for scrollTop? 为什么不$('.media.unread').offset().top scrollTop使用$('.media.unread').offset().top I think, you can get it. 我认为,您可以得到它。

If I have a mistake, please tell me details!! 如果我有错,请告诉我细节!!

Thx 谢谢

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

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