update jump link behavior

This commit is contained in:
Ryan Haskell-Glatz 2019-10-19 02:06:40 -05:00
parent 4592a368d2
commit 62f2134ba3
3 changed files with 15 additions and 6 deletions

View File

@ -7,6 +7,7 @@ module Pages.Counter exposing
import Application
import Html exposing (..)
import Html.Attributes as Attr
import Html.Events as Events
@ -57,5 +58,8 @@ view model =
[ button [ Events.onClick Decrement ] [ text "-" ]
, p [] [ text (String.fromInt model.counter) ]
, button [ Events.onClick Increment ] [ text "+" ]
, p []
[ a [ Attr.href "/#section" ] [ text "bottom of homepage" ]
]
]
]

View File

@ -7,6 +7,7 @@ module Pages.Homepage exposing
import Application
import Html exposing (..)
import Html.Attributes as Attr
type alias Model =
@ -33,4 +34,8 @@ view =
div []
[ h1 [] [ text "Homepage" ]
, p [] [ text "How exciting!" ]
, a [ Attr.href "#section" ] [ text "jump link" ]
, div [ Attr.style "height" "200vh" ] []
, h3 [ Attr.id "section" ] [ text "you found me!" ]
, p [] [ text "(and i'm not even mad)" ]
]

View File

@ -14,6 +14,7 @@ module Application exposing
@docs Application, create
@docs Page, Recipe
@docs Bundle, keep
@docs Static, static
@ -190,9 +191,12 @@ update config msg model =
( model, Cmd.none )
Link (Browser.Internal url) ->
if url == model.url then
if url == model.url && url.fragment == Nothing then
( model, Cmd.none )
else if url.path == model.url.path then
( model, Nav.load (Url.toString url) )
else
( { model | page = Transition.begin model.page }
, Utils.delay config.speed (TransitionTo url)
@ -205,11 +209,7 @@ update config msg model =
TransitionTo url ->
( model
, if url.path == model.url.path then
Nav.load (Url.toString url)
else
Nav.pushUrl model.key (Url.toString url)
, Nav.pushUrl model.key (Url.toString url)
)
TransitionComplete ->