PageSourceSearch

https://www.ipcc.ch/site/assets/themes/ipcc/resources/bower_components/pe-smooth-scroll/smooth-scroll.js

js ipcc.ch collected 2026-09-24 06:44:22 UTC 2,577 bytes, 87 lines download raw bytes

1// smooth scroll
2// v1.1
3
4(function ($) {
5    
6  $.fn.smooth_scroll = function(options) {
7  
8    // options
9  
10    var defaults = {
11      viewport: $('html, body'),
12      id: this.attr('href'),
13      ease: 'swing',
14      offset: 0,
15      speed: 500,
16      cancel: true,
17      callback: null,
18      logging: false
19    };
20    
21    var settings = $.extend(true, defaults, options);
22      
23    if ($(settings.id).length) {
24    
25      // viewport's position in the window
26      var viewport_position = settings.viewport.offset().top;
27      
28      // viewport's scroll position
29      var viewport_scrolltop = settings.viewport.scrollTop();
30      
31      if (typeof settings.viewport == 'object') {
32        var viewport_object = settings.viewport[settings.viewport.length - 1];
33        viewport_scrolltop = $(viewport_object).scrollTop();
34      }
35      
36      // element's position in the window
37      var element_position = $(settings.id).offset().top;
38      
39      // current scroll position PLUS the element's position (offset by the viewport's position)
40      //var destination = (viewport_scrolltop + (element_position - viewport_position)) - settings.offset;
41      var destination = element_position - settings.offset;
42
43      if (settings.logging == true) {
44        console.log('id', settings.id);
45        console.log('viewport’s position in the window', viewport_position);
46        console.log('viewport’s current scroll position', viewport_scrolltop);
47        console.log('target element’s position', element_position);
48        console.log('final scroll position', destination);
49        
50        console.log('scroll ' + settings.viewport.attr('id') + ' to ' + destination + ' so that ' + settings.id + ' is in view');
51      }
52      
53      if (settings.cancel === true) {
54        settings.viewport.on("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove", function(){
55          settings.viewport.stop();
56        });
57      }
58    
59      settings.viewport.animate({
60        scrollTop: destination
61      }, {
62        duration: settings.speed, 
63        easing: settings.ease,
64        complete: function() {
65          settings.viewport.off("scroll mousedown wheel DOMMouseScroll mousewheel keyup touchmove");
66        }
67      }).promise().then(function() {
68        
69        if (typeof(settings.callback) == 'function') {
70          settings.callback.call(this)
71        }
72        
73      });
74      
75      
76      
77    } else {
78      
79      if (settings.logging == true) {
80        console.log(settings.id + ' does not exist');
81      }
82      
83    }
84    
85  }
86  
87}(jQuery));

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.