Scroll to a specific position on a page using Javascript / Jquery

This question already has an answer here: jQuery jump or scroll to certain position, div or target on the page from button onclick [duplicate] 2 answers jQuery scroll to element 24 answers 经过大量的搜索,我发现你只需要这样做: location.hash = "elementId" 以下是我使用浏览器控制台在今日纽约时报首页上测试的一个示例函数: function scrollToElement(pageElement) { var positionX = 0,

使用Javascript / Jquery滚动到页面上的特定位置

这个问题在这里已经有了答案: jQuery跳转或滚动到某个位置,div或target上的按钮onclick [复制] 2个答案 jQuery滚动到元素24的答案 经过大量的搜索,我发现你只需要这样做: location.hash = "elementId" 以下是我使用浏览器控制台在今日纽约时报首页上测试的一个示例函数: function scrollToElement(pageElement) { var positionX = 0, positionY = 0; while(pageElement != null){

Strange Date behavior in Chrome

Why these nearly similar date objects give different results in Chrome 37? var d2014 = new Date(2014, 0, 1); alert(d2014.getFullYear()); // 2013 var d2015 = new Date(2015, 0, 1); alert(d2015.getFullYear()); // 2015 In IE11 I get "2014" and "2015" as expected. Browser works in Russian locale. Conversion to strings gives the following results: d2014.toString(); // Tue D

Chrome中的奇怪日期行为

为什么这些几乎相似的日期对象在Chrome 37中有不同的结果? var d2014 = new Date(2014, 0, 1); alert(d2014.getFullYear()); // 2013 var d2015 = new Date(2015, 0, 1); alert(d2015.getFullYear()); // 2015 在IE11中,我预计会得到“2014”和“2015”。 浏览器在俄语区域设置。 转换为字符串会得到以下结果: d2014.toString(); // Tue Dec 31 2013 23:00:00 GMT+0300 (RTZ 2 (зима)) d2015.toString(); // Thu Jan 0

Cross browser JavaScript (not jQuery...) scroll to top animation

I'm looking for a simple, cross-browser "scroll to top" animation I can apply to a link. I don't want to require a JS library such as jQuery/Moo, etc. // jQuery Equivilant to convert to pure JS... $('html, body').animate({scrollTop:0}, 400); I'm a perfect case for someone who should have learned JS 100% before jumping into a library. :( function scrollTo(element, to, du

跨浏览器JavaScript(不是jQuery ...)滚动到顶部动画

我正在寻找一个简单的跨浏览器“滚动到顶部”动画,我可以将它应用到链接。 我不想要JS库,如jQuery / Moo等。 // jQuery Equivilant to convert to pure JS... $('html, body').animate({scrollTop:0}, 400); 对于那些在跳入图书馆之前应该学习JS 100%的人来说,我是一个完美的例子。 :( function scrollTo(element, to, duration) { if (duration <= 0) return; var difference = to - element.scrollTop; v

Lagging animation in Safari but not in Chrome

I've implemented a background animation exactly likes this reference: https://tympanus.net/Development/ShapeMorphIdeas/index3.html What I'm noticing in both my implementation and the example is that Safari lags hard while that animation is active. What also happens is that while the animation is active in Safari my whole computer runs slow. However, when I open either one in Chrome I

在Safari中滞后的动画,但不在Chrome中

我已经实现了一个完全喜欢这个参考的背景动画:https://tympanus.net/Development/ShapeMorphIdeas/index3.html 在我的实现和示例中,我注意到Safari在动画活动时滞后。 还会发生的是,虽然动画在Safari中处于活动状态,但我的整个计算机运行缓慢。 但是,当我在Chrome中打开任何一个时,我都没有任何性能问题。 这个问题是特定于Safari,还是Safari和计算机的组合,还是完整的计算机图形问题? 这些是我的环境规格 :

GIF not working with form submission in Safari but works in Chrome

I want to run a GIF animation as a loader while a form is being submitted. I have made a very basic form with just a input button which once clicked submits the form and also should get replaced by the GIF.The GIF does not work in Safari but works in Chrome. Client requirement is that the GIF should run in all browsers. Another requirement is that I cannot use AJAX to submit the form as recomm

GIF不能在Safari中使用表单提交,但可在Chrome中使用

我想在提交表单时作为加载器运行GIF动画。 我做了一个非常基本的表单,只有一个输入按钮,一旦点击提交表单,也应该被GIF取代.GIF在Safari中不工作,但在Chrome中工作。 客户的要求是GIF应该在所有浏览器中运行。 另一个要求是我不能按照这个答案中推荐的方式使用AJAX提交表单。 我的jQuery $(document).ready(function(){ $("#myform").on("submit", function(){ $(".UploadBtn").hide(); $("#spinner

Animated HTML Canvas background suddenly not working in Chrome

So for my personal website, I created an animated background using JavaScript and HTML Canvas. It worked fine on Firefox, Chrome, Safari, etc. but I recently went to check on it and suddenly the animation isn't working in Chrome. It actually works in Chrome for mobile, but it doesn't work in Chrome desktop, which makes me think they must have changed something. To set the background,

动画HTML画布背景在Chrome中突然不起作用

所以对于我的个人网站,我使用JavaScript和HTML Canvas创建了动画背景。 它在Firefox,Chrome,Safari等上运行良好,但我最近去检查它,突然间动画在Chrome中无法使用。 它实际上适用于移动版的Chrome,但在Chrome桌面无法使用,这让我认为他们必须改变某些内容。 要设置背景,我使用下面的代码: <div class="info" style="background:-webkit-canvas(background) repeat;"> <div class="

Safari 7.0.3 animate ScrollTop div not working?

I'm having trouble getting a #div with overflow:scroll to animate and scroll down to a specific part within the div in Safari 7.0.3. It works just fine in FF, Opera, Chrome, but I can't get it to work in Safari for some reason? Does anybody know why and how I can work around this? I've tried setting the #menuContainer to relative positioning, and it works but badly. It will work

Safari 7.0.3 animate ScrollTop div不工作?

我无法获得带有溢出的#div:滚动到动画并向下滚动到Safari 7.0.3中div的特定部分。 它在FF,Opera,Chrome中运行得很好,但由于某些原因我无法在Safari中使用它? 有人知道为什么以及如何解决这个问题? 我已经尝试将#menuContainer设置为相对定位,并且它的工作原理很糟糕。 它有时会工作,有时候不会。 CSS #menu{ position:absolute; display: block; right: 0; } #menuContainer{ position:absolute; ov

Changing <source> with HTML5 Audio works in Chrome but not Safari

I'm trying to make an HTML5 audio playlist that will work in each major browser: Chrome,Safari, Firefox, IE9+. However, I can't figure out how to change the sources in a cross browser compatible way. UPDATED For example, changing the <source> tag's src s works in Chrome but not Safari. While @eivers88's solution below using canPlayType works it seems easier to me just to

使用HTML5更改<source>音频可在Chrome浏览器中使用,但不支持Safari

我试图制作一个HTML5音频播放列表,可以在各个主要浏览器中使用:Chrome,Safari,Firefox,IE9 +。 但是,我无法弄清楚如何以跨浏览器兼容的方式更改源代码。 已更新例如,更改<source>标记的src可在Chrome中运行,但不能在Safari中运行。 虽然@ eivers88的下方采用溶液canPlayType作品似乎更容易我只是改变<source>标签的src秒。 任何人都可以向我解释为什么我的代码直接在Chrome下运行,但不是Safari? JS

How to detect Safari, Chrome, IE, Firefox and Opera browser?

I have 5 addons / extensions for FF, Chrome, IE, Opera and Safari. I need the code to recognize the user browser and redirect (on click in an install button) to download the corresponding addon. Googling for browser reliable detection often results in checking the User agent string. This method is not reliable, because it's trivial to spoof this value. I've written a method to dete

如何检测Safari,Chrome,IE,Firefox和Opera浏览器?

我有FF,Chrome,IE,Opera和Safari 5个插件/扩展。 我需要代码来识别用户浏览器并重定向(点击安装按钮)以下载相应的插件。 Google浏览器可靠检测通常会导致检查用户代理字符串。 这种方法不可靠,因为欺骗这个值是微不足道的。 我已经编写了一种通过鸭式打印来检测浏览器的方法。 如果真的有必要,请仅使用浏览器检测方法,例如显示特定于浏览器的指令来安装扩展。 尽可能使用功能检测。 演示:https://jsfiddle

load and execute order of scripts

There are so many different ways to include JavaScript in a html page. I know about the following options: inline code or loaded from external URI included in <head> or <body> tag [1,2] having none, defer or async attribute (only external scripts) included in static source or added dynamically by other scripts (at different parse states, with different methods) Not counting

加载并执行脚本的顺序

在html页面中包含JavaScript的方式有很多种。 我知道以下选项: 内联代码或从外部URI加载 包含在<head>或<body>标记中[1,2] 没有, defer或async属性(只有外部脚本) 包含在静态源代码中或由其他脚本动态添加(在不同的分析状态下,使用不同的方法) 从硬盘,javascript:URI和onEvent -attributes [3]中不计算browserscripts,已经有16个替代品来执行JS,我确信我忘了一些东西。 我并不担心快速(并