Print result of .scrollTop in jQuery -


I am trying to show the value of the .scrollTop () function on the screen while scrolling up and down on the screen, but I can not get it to work. I'm clearly doing something stupid. Please let me know. :) Thanks. & lt; Body & gt; & Lt; Div id = "mydiv" & gt; & Lt; P & gt; ..... & lt; / P & gt; & Lt; / Div & gt; & Lt; Div id = "tall" & gt; & Lt; / Div & gt; & Lt; Script & gt; Var $ myVar = $ ('# myDiv'); Var $ myDist = $ window.scrollTop (); $ Window.on ('scroll', function () {$ myVar.text ($ myDist);}); & Lt; / Script & gt; & Lt; / Body & gt;

Here's a bella:

OK, the solution was done to cache the window, and insert .ccrollTop () inside the curly braces. thanks for your cooperation. :)

Solution:

  var $ window = $ (window); Var $ myVar = $ ('# myDiv'); Var $ myDist = 0; $ Window.on ('scroll', function () {$ myDist = $ window.scrollTop (); $ myVar.html ($ myDist);});    

Hope this helps

  $ (Window) .scroll (function () {var scrps = $ (this) .scrollTop (); $ ('# myDiv') .html ('your scroll position is' + scrpos);});   

Here I got Scroll Postien and it has been added in the form of html in the id in which the ID is '#myDiv'

working here For more details on

scroll

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -