Answer the question
In order to leave comments, you need to log in
How to fire an ajax request when scrolling to an element?
Hello dear programmers!
There is a news feed. And there is an opportunity to go to the page for viewing a specific news.
But not all news require a transition, in the sense that it consists, for example, of only one picture and it makes no sense to follow the link.
And I would like to fasten the counter of viewing each news.
When a person goes to the news, there are no problems, but just when scrolling the feed, how to correctly implement the launch of an ajax request to update the data?
And there may be some way to save the data so that if a person has already "checked in" in the views, then ajax would not be re-run on him if he scrolls through the feed again, but naturally does not reload the page. After the reboot, the data will already be checked from the database.
The problem is that with the same element class, the function only works up to the first similar element. And if you make dynamic data, let's say the Id of the element, then how then to tell the script which element to catch?
There is an option to hang up the launch of the function when you hover over the news area, but if the cursor is on the side, at the time of scrolling, from the main feed, then the view will not be counted.
Answer the question
In order to leave comments, you need to log in
On a site with less aggressive users, they offered an option for 2.4 mongi
heh = list(db.events.aggregate(
[
{"$match": {"status": 'start'}},
{"$group": {"_id": "$eventName", "players": {"$addToSet": "$uid"}}},
{"$unwind": "$players"},
{"$group": {"_id": "$_id", "Count": {"$sum": 1}}},
]))
Track scroll...
If the scroll passed the checkpoint, i.e. the block with the news, then run it.
And as for checks, you need to identify the user, for example, by cookies ... and write down in cookies what news he watched, and before loading the page, check this cookie and set disabled for those viewed ...
something like this
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question