Is there a way to determine whether the current element appears with the use of jQuery on the user's screen / viewport? (Not using other external libraries)
Not directly using the default jQuery, but you You can implement your own function, which you can use later on a jQuery element:
(function ($) {$ .fn.isOnScreen = function () {var Topview = $ (Window) .scrollTop (); var botView = TopVV + $ (window) .it (); var top element = this.offetset (top); topBotAllimate = top element + this.height (); Return (Boatley Ent & lt; = Botwu) & amp; amp; amp; & amp; (Topelement & gt; = TOP weave));}}) (jQuery); After adding this code, you can call $ ('#ElementId'). IsOnScreen ()
will return true
if the whole element is on the screen and false
if it is not.
You can play with it a bit, so it will return true
, if for at least one example:
(Function ($) {$ .fn.isOnScreen = function () {var topview = $ (window) .scrollTop ()); Var botView = Top Viv + $ (window). height (); Var top element = this.offet (). Top; Var bottlement = top element + (this.height () / 4); // & lt; --- Returns ((Botlement & Lt; = botview) & amp; amp; (top element & gt; = top view));}}) ();
Comments
Post a Comment