Created
March 4, 2016 21:08
-
-
Save ob/cf03407ee108ca0d2b56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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