Skip to content

Instantly share code, notes, and snippets.

@ob
Created March 4, 2016 21:08
Show Gist options
  • Save ob/cf03407ee108ca0d2b56 to your computer and use it in GitHub Desktop.
Save ob/cf03407ee108ca0d2b56 to your computer and use it in GitHub Desktop.
<script type ="text/javascript">
var app = Elm.fullscreen(Elm.Main, {
lastItemVisible: false
});
window.onscroll = function () {
var wrapper = document.getElementsByClassName("cset-list")[0];
var lastItem = wrapper.childNodes[wrapper.childNodes.length - 1];
console.log("last item offset: " + wrapper.childNodes.length);
if (isElementInViewport(lastItem)) {
app.ports.lastItemVisible.send(true);
console.log("sent true: " + lastItem);
} else {
app.ports.lastItemVisible.send(false);
console.log("sent false: " + lastItem);
}
};
</script>
type alias Model =
{
-- bunch of fields
, isLastItemVisible : Bool
}
type Action
= None
-- bunch of actions
| UpdateLastItemVisible Bool
update: Action -> Model -> (Model, Effects Action)
update action model =
case action of
-- bunch of actions
UpdateLastItemVisible b ->
( { model | isLastItemVisible = b }, Effects.none )
view: Address Action -> Model -> Html
view address model =
-- bunch of html things
[ h2 [] [ text (if model.isLastItemVisible then "Visible" else "Nope") ] ]
port lastItemVisible : Signal Bool
lastItemVisibleActions: Signal Action
lastItemVisibleActions =
Signal.map (\b -> UpdateLastItemVisible b) lastItemVisible
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment