scroll

package
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2023 License: GPL-2.0 Imports: 9 Imported by: 0

README

Simple scrollable SPA

Here you can see how to create a simple scrollable single page application.

func main() {
	var Application = scroll.App("#app", &scroll.Options{
		ScrollAxis:    scroll.ScrollAxisX,
		ScrollThrough: true,
		ClassPrefix:   "scrollable-app",
	})
	var Mainmenu = menus.NewMenuOptions(menus.Left)
	Mainmenu.CSSMap[menus.OverlayBackgroundColor] = "rgba(0,0,0,0.8)"
	Mainmenu.URLs.FromElements(true,
		elements.A("#home", "Home"),
		elements.A("#about", "About"),
		elements.A("#contact", "Contact"),
	)
	Application.SetNavbar(menus.Blurry(Mainmenu))
	var colorbgs = Application.Backgrounds(scroll.BackgroundTypeColor, "#ff0000", "#9200ff", "#0000ff")
	var imgbgs = Application.Backgrounds(scroll.BackgroundTypeImage, "/static/1.png")

	colorbgs[0].AddGradient(scroll.GradientTypeRadial, "circle", "rgba(0,0,0,0.4)", "rgba(255, 255, 255, 0.2)")
	colorbgs[1].AddGradient(scroll.GradientTypeLinear, "to right", "rgba(0,0,0,0.4)", "rgba(255, 255, 255, 0.2)")
	imgbgs.AddGradient(scroll.GradientTypeRadial, "circle", "rgba(0,0,0,0.4)", "rgba(152, 92, 255, 0.2)")

	var pageNames = []string{"home", "about", "contact"}
	for _, name := range pageNames {
		var title = elements.H1(name)
		var text = elements.P("Welcome to the " + name + " page.")
		title.Animations.FadeIn(500, elements.UseIntersectionObserver, true)
		text.Animations.FadeIn(500, elements.UseIntersectionObserver, true)
		var page = elements.Div().AttrStyle("color:white;").Append(
			title,
			text,
		)
		Application.AddPage(name, page)
	}

	Application.Run()
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

type Application struct {
	Loader components.Loader

	Options *Options
	// contains filtered or unexported fields
}

Application struct

func App

func App(documentObjectQuerySelector string, options *Options) *Application

Create a new application from options

func (*Application) AddPage

func (s *Application) AddPage(title string, c components.ComponentWithValue) *Page

Add a page

func (*Application) Backgrounds

func (s *Application) Backgrounds(t BackgroundType, b ...string) Backgrounds

Set the application backgrounds

func (*Application) Client

func (a *Application) Client() *requester.APIClient

Initialize a http client with a loader for a new request.

func (*Application) Close

func (s *Application) Close()

Exit the application.

func (*Application) ContainerByName

func (s *Application) ContainerByName(name string) jsext.Element

containerByName returns the page's container by name.

func (*Application) CurrentPage

func (s *Application) CurrentPage() *Page

func (*Application) NextPage

func (s *Application) NextPage()

Go to the next page

func (*Application) PageByHash

func (s *Application) PageByHash(name string) (*Page, int)

PageByHash returns the page by the hash value.

func (*Application) PageByTitle

func (s *Application) PageByTitle(name string) (*Page, int)

PageByTitle returns the page by the title.

func (*Application) PreviousPage

func (s *Application) PreviousPage()

Go to the previous page

func (*Application) Run

func (s *Application) Run()

Run the application

func (*Application) SetClientFunc

func (a *Application) SetClientFunc(f func() *requester.APIClient) *Application

Set the client function.

func (*Application) SetFooter

func (s *Application) SetFooter(c components.Component)

Set the application footer

func (*Application) SetLoader

func (s *Application) SetLoader(loader components.Loader)

Set the application loader

func (*Application) SetNavbar

func (s *Application) SetNavbar(c components.Component)

Set the application navbar

type Axis

type Axis int8

Axis to scroll on.

const (
	ScrollAxisX Axis = 1
	ScrollAxisY Axis = 2
)

Axis to scroll on.

type Background

type Background struct {
	BackgroundType BackgroundType
	Background     string
	ExtraCSS       string
	Gradient       *Gradient
}

Background is a struct that holds the type of background and the background styling.

func (*Background) AddGradient

func (b *Background) AddGradient(gradientType GradientType, direction string, g ...string)

Gradient type can only be set once! Gradients will be passed along in the following css string: background: linear-gradient(to boottom, gradient1, gradient2, ...);

func (*Background) CSS

func (bg *Background) CSS(selector string) string

type BackgroundType

type BackgroundType int8

Supported background types for the scrollable app.

const (
	BackgroundTypeImage BackgroundType = 1
	BackgroundTypeColor BackgroundType = 2
	BackgroundTypeStyle BackgroundType = 3
)

Supported background types for the scrollable app.

type Backgrounds

type Backgrounds []*Background

Backgrounds is a slice of Backgrounds.

func (Backgrounds) AddGradient

func (b Backgrounds) AddGradient(gradientType GradientType, direction string, g ...string)

type Gradient

type Gradient struct {
	GradientType GradientType
	Direction    string
	Gradients    []string
}

Gradient is a struct that holds the type of gradient and the gradients.

func (*Gradient) String

func (g *Gradient) String() string

type GradientType

type GradientType int8

Type of gradient to use.

const (
	GradientTypeLinear GradientType = 1
	GradientTypeRadial GradientType = 2
)

Type of gradient to use.

type Options

type Options struct {
	ScrollAxis    Axis
	ClassPrefix   string
	ScrollThrough bool
}

Application options

type Page

type Page struct {
	Component components.ComponentWithValue
	OnShow    func(element components.ComponentWithValue, p PageDirection)
	OnHide    func(element components.ComponentWithValue, p PageDirection)
	// contains filtered or unexported fields
}

Page struct. Mostly used internally.

func (*Page) SetOnHide

func (p *Page) SetOnHide(cb func(element components.ComponentWithValue, p PageDirection)) *Page

Callback for when the page is being hidden.

func (*Page) SetOnShow

func (p *Page) SetOnShow(cb func(element components.ComponentWithValue, p PageDirection)) *Page

Callback for when the page is being viewed.

type PageDirection

type PageDirection int8
const (
	Initial PageDirection = 0
	Up      PageDirection = 1
	Down    PageDirection = 2
	Left    PageDirection = 3
	Right   PageDirection = 4
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL