Scrollspy

Japan Listeni/dʒəˈpæn/ (Japanese: 日本 Nippon or Nihon; formally 日本国 About this sound Nippon-koku or Nihon-koku, literally "the State of Japan") is an island nation in East Asia. Located in the Pacific Ocean, it lies to the east of the Sea of Japan, China, North Korea, South Korea and Russia, stretching from the Sea of Okhotsk in the north to the East China Sea and Taiwan in the south. The characters that make up Japan's name mean "sun-origin", which is why the country is sometimes referred to as the "Land of the Rising Sun". Japan is an archipelago of 6,852 islands, the four largest being Honshu, Hokkaido, Kyushu and Shikoku. Together, these four islands hold about 97 percent of the country's land area. Japan has the world's tenth-largest population, with more than 126 million people. Honshū's Greater Tokyo Area includes the de facto capital city of Tokyo and several surrounding prefectures. It is the largest metropolitan area in the world, with more than 30 million residents.

Japan Listeni/dʒəˈpæn/ (Japanese: 日本 Nippon or Nihon; formally 日本国 About this sound Nippon-koku or Nihon-koku, literally "the State of Japan") is an island nation in East Asia. Located in the Pacific Ocean, it lies to the east of the Sea of Japan, China, North Korea, South Korea and Russia, stretching from the Sea of Okhotsk in the north to the East China Sea and Taiwan in the south. The characters that make up Japan's name mean "sun-origin", which is why the country is sometimes referred to as the "Land of the Rising Sun". Japan is an archipelago of 6,852 islands, the four largest being Honshu, Hokkaido, Kyushu and Shikoku. Together, these four islands hold about 97 percent of the country's land area. Japan has the world's tenth-largest population, with more than 126 million people. Honshū's Greater Tokyo Area includes the de facto capital city of Tokyo and several surrounding prefectures. It is the largest metropolitan area in the world, with more than 30 million residents.

Japan Listeni/dʒəˈpæn/ (Japanese: 日本 Nippon or Nihon; formally 日本国 About this sound Nippon-koku or Nihon-koku, literally "the State of Japan") is an island nation in East Asia. Located in the Pacific Ocean, it lies to the east of the Sea of Japan, China, North Korea, South Korea and Russia, stretching from the Sea of Okhotsk in the north to the East China Sea and Taiwan in the south. The characters that make up Japan's name mean "sun-origin", which is why the country is sometimes referred to as the "Land of the Rising Sun". Japan is an archipelago of 6,852 islands, the four largest being Honshu, Hokkaido, Kyushu and Shikoku. Together, these four islands hold about 97 percent of the country's land area. Japan has the world's tenth-largest population, with more than 126 million people. Honshū's Greater Tokyo Area includes the de facto capital city of Tokyo and several surrounding prefectures. It is the largest metropolitan area in the world, with more than 30 million residents.

Japan Listeni/dʒəˈpæn/ (Japanese: 日本 Nippon or Nihon;...

Japan Listeni/dʒəˈpæn/ (Japanese: 日本 Nippon or Nihon;...

Japan Listeni/dʒəˈpæn/ (Japanese: 日本 Nippon or Nihon;...

document.querySelector('[data-spy="scroll"]').scrollspy
	offset: 100

Properties

Name Default Description
spy @el.getAttribute( 'data-spy' ) or 'scroll' Set spying type.
target @el.getAttribute( 'data-target' ) or 'body' Listen to event scroll of this element. All spying blocks are inside.
offset @el.getAttribute( 'data-offset' ) or 5 Vertical offset of the element in text to fire the activation (for example activate menu when the header will be 5px above the top of the screen).
elements @el.getAttribute( 'data-elements' ) or 'li a' Selector to spy those elements inside @ (spy, or menu in our case).
elementsAttr @el.getAttribute( 'data-elements-attr' ) or 'href' Attribute of each element with ID of the target.
onMobile @el.getAttribute( 'data-on-mobile' ) or no Deactivate spy on mobile devices.

Methods

Method Description
start

Activate spy.

stop

Deativate spy.

refresh

Refresh all menu items and positions of targets.

Events

Inside each method to get menu element use @ or this in js. Class instance always stores in data attribute of the menu element @data['kitScrollspy'] or this.data['kitScrollspy'] in js. To get scrollspy element (menu) do @data['kitScrollspy'].el. To get scrollspy scroll block do @data['kitScrollspy'].target.
Method Description
beforeactive

Set a function to call it before activate the spy. If it returns deferred.promise(), then spy will not start till deferred.resolve(), and woun't start if deferred.reject().

document.querySelector('.spy-this-menu').scrollspy
	beforeactive: ->
		d = $.Deferred()

		console.log @
		# The spy (menu) will be in the log
		# so you can, for example, add classes
		# to disable the spying menu

		console.log @data['kitScrollspy']
		# The instance of Scrollspy class will in log
		# so to get scrollspy element you need to do
		spy = @data['kitScrollspy']
		spy._addClass '_disabled_'

		# Do something here before activate scrollspy
		# in this case it will start in 2 seconds
		setTimeout ->
			d.resolve()
		, 2000
		# End of your code

		d.promise()

onactive

Set a function to call it after spy started.

failactive

Set a function to call it if starting failed.

beforedeactive

Call this function before spy stopped.

ondeactive

Call this function after spy stopped.

faildeactive

Set a function to call it if stopping failed.