{"action":"created","issue":{"url":"https://api.github.com/repos/janpaepke/ScrollMagic/issues/281","labels_url":"https://api.github.com/repos/janpaepke/ScrollMagic/issues/281/labels{/name}","comments_url":"https://api.github.com/repos/janpaepke/ScrollMagic/issues/281/comments","events_url":"https://api.github.com/repos/janpaepke/ScrollMagic/issues/281/events","html_url":"https://github.com/janpaepke/ScrollMagic/issues/281","id":64677538,"number":281,"title":"Calling a function when an element scrolls into view","user":{"login":"BenjoJ","id":11658042,"avatar_url":"https://avatars.githubusercontent.com/u/11658042?v=3","gravatar_id":"","url":"https://api.github.com/users/BenjoJ","html_url":"https://github.com/BenjoJ","followers_url":"https://api.github.com/users/BenjoJ/followers","following_url":"https://api.github.com/users/BenjoJ/following{/other_user}","gists_url":"https://api.github.com/users/BenjoJ/gists{/gist_id}","starred_url":"https://api.github.com/users/BenjoJ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BenjoJ/subscriptions","organizations_url":"https://api.github.com/users/BenjoJ/orgs","repos_url":"https://api.github.com/users/BenjoJ/repos","events_url":"https://api.github.com/users/BenjoJ/events{/privacy}","received_events_url":"https://api.github.com/users/BenjoJ/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/janpaepke/ScrollMagic/labels/support","name":"support","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-03-27T02:42:35Z","updated_at":"2015-03-31T00:17:11Z","closed_at":"2015-03-31T00:17:11Z","body":"Hi\r\n\r\nMy requirement is to call a function when an element scrolls into view. The trigger will be selected based on the class, and I will need to get the ID of the element it has selected. \r\n\r\nSo, as the user scrolls down and a new instance of this class appears (at the bottom of the viewport when scrolling down or the top of the viewport when scrolling up), I would like to call a function.\r\n\r\nIs this possible with ScrollMagic? I have tried lots of different things but cannot get anything to fit what I need it to do. An example of what I have tried is below, but this is only called when the page first loads, and returns 'undefined'.\r\n\r\n```js\r\n\ttween = new TimelineMax()\r\n\t\t\t.add(function () { alert(jQuery(this).attr('id')) })\r\n\r\n\tscene_GetCurrentScreen = new ScrollMagic.Scene({ triggerElement: \".Screen\", duration: 100, offset: 0 })\r\n\t\t\t\t\t.setTween(tween)\r\n\t\t\t\t\t.addTo(controller);\r\n```\r\nThanks so much for your help, and keep up the good work. What you have done here is superb.\r\n\r\nBen"},"comment":{"url":"https://api.github.com/repos/janpaepke/ScrollMagic/issues/comments/87882296","html_url":"https://github.com/janpaepke/ScrollMagic/issues/281#issuecomment-87882296","issue_url":"https://api.github.com/repos/janpaepke/ScrollMagic/issues/281","id":87882296,"user":{"login":"BenjoJ","id":11658042,"avatar_url":"https://avatars.githubusercontent.com/u/11658042?v=3","gravatar_id":"","url":"https://api.github.com/users/BenjoJ","html_url":"https://github.com/BenjoJ","followers_url":"https://api.github.com/users/BenjoJ/followers","following_url":"https://api.github.com/users/BenjoJ/following{/other_user}","gists_url":"https://api.github.com/users/BenjoJ/gists{/gist_id}","starred_url":"https://api.github.com/users/BenjoJ/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BenjoJ/subscriptions","organizations_url":"https://api.github.com/users/BenjoJ/orgs","repos_url":"https://api.github.com/users/BenjoJ/repos","events_url":"https://api.github.com/users/BenjoJ/events{/privacy}","received_events_url":"https://api.github.com/users/BenjoJ/received_events","type":"User","site_admin":false},"created_at":"2015-03-31T00:17:11Z","updated_at":"2015-03-31T00:17:11Z","body":"That worked perfectly Jan, thanks so much for your help.\r\n\r\n\tjQuery('.Screen').each(function () {\r\n\t\tvar currentScreen = this;\r\n\t\tnew ScrollMagic.Scene({ triggerElement: currentScreen, duration: 2000, offset: iScreenSize_H })\r\n\t\t\t.on('start', function () {\r\n\t\t\t\tconsole.log(this.triggerElement().id);\r\n\t\t\t}).addTo(controller);\r\n\t});"}}