小编ric*_*hie的帖子

jQuery使用下一个/上一个按钮滚动到下一个Div类

我想要的是固定导航,使用NEXT和PREV按钮基本上将页面滚动到下一个具有"section"类的div.

我已经设置了jQuery,实际上是为NEXT和PREV hrefs添加了一个click函数.然后,此单击函数将使用ScrollTop移动到具有.section类的下一个duv.

这是jQuery:

$('div.section').first();
// binds a click event-handler to a elements whose class='display'
$('a.display').on('click', function(e) {
    // prevents the default action of the link
    e.preventDefault();
    // assigns the text of the clicked-link to a variable for comparison purposes
    var t = $(this).text(),
      that = $(this);
      console.log(that.next())    
      // checks if it was the 'next' link, and ensures there's a div to show after the currently-shown one
      if (t === 'next' && that.next('div.section').length > 0) {
      //Scroll Function
      $('html, body').animate({scrollTop:that.next('div.section').scrollTop()}); …
Run Code Online (Sandbox Code Playgroud)

javascript jquery frontend scroll

7
推荐指数
1
解决办法
2万
查看次数

多个异步AJAX调用最佳实践

关于在单个页面上进行多个AJAX调用的"最佳实践",我有一个问题.

我需要异步进行5次隔离调用.我知道$ .ajax本质上是异步的,但我很好奇是否有更"清洁"或"更好"的方式来做多个AJAX调用.

包含多个AJAX调用的示例如下:

$(function() {
  $.ajax({
    type: "GET",
    url: "https://api.github.com/users/ralvarenga",
    dataType: "json",
    success: function(data) { console.log(data); }
  });
  $.ajax({
    type: "GET",
    url: "https://api.github.com/users/dkang",
    dataType: "json",
    success: function(data) { console.log(data); }
  });
});
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的帮助!

javascript api ajax jquery asynchronous

4
推荐指数
1
解决办法
3735
查看次数

Javascript代码结构 - 这是如何工作的?

我偶然发现了一种非常优雅的方式来构建一个页面的JS代码,尽管我不确定它为什么会像它那样工作.有人可以向我解释这是如何工作的吗?(为什么那里有返回声明).

还有一个名称来描述这样的模式吗?

var PageCode = (function () {

    return {
        ready: function () {
            console.log('document.ready');
        },
        load: function() {
            console.log('document.load');
        }
    };
}());

$(document).ready(PageCode.ready);
$(window).load(PageCode.load);
Run Code Online (Sandbox Code Playgroud)

javascript

3
推荐指数
1
解决办法
229
查看次数

标签 统计

javascript ×3

jquery ×2

ajax ×1

api ×1

asynchronous ×1

frontend ×1

scroll ×1