Pesquisar neste blog

08/07/2021

Plugin #02 com jQuery em HTML

TEMPORIZADOR EM HTML USANDO jQuery

Arquivo: estilo.css
@font-face {
    font-family'Oswald';
    srcurl('../fonts/Oswald-Regular.ttf'format('truetype');
}

*{
    font-family'Oswald'sans-serif;
}

html {
    height100%;
}

body {
    margin0;
    background-color#0D262D;
    color#fff;
    height100%;
}

table {
    border-collapsecollapse;
}

tr {
    border-bottomsolid 1px white;
}

td {
    font-size1.6em;
    padding10px;
}

li {
    font-size1.6em;
}

.conteudo {
    displayflex;
    flex-directioncolumn;
    align-itemscenter;
    min-height100%;
}

.exercicio div {
    font-size1.8em;
    bordersolid 5px #fff;
    padding0px 40px;
    margin10px;
}

.exercicio div:nth-of-type(1) {
    background-colordarkgoldenrod;
}

.exercicio div:nth-of-type(2) {
    background-colorcrimson;
}

.exercicio div:nth-of-type(3) {
    background-colordarkcyan;
}

.exercicio div:nth-of-type(4) {
    background-colordarkorchid;
}

.exercicio div:nth-of-type(5) {
    background-colordodgerblue;
}

.exercicio div:nth-of-type(6) {
    background-colorsalmon;
}

.exercicio .destaque {
    bordersolid 10px greenyellow;
    colorgreenyellow;
    font-weightbold;
}

Arquivo: temporizador.js
(function ($) {
    $.fn.temporizador = function (opcoes) {
        const opcoesFinais = $.extend({
            mensagem: 'Em breve!',
            horario: '23:59:59'
        }, opcoes)

        const horaDezena = $('<span class="digito">').html('0')
        const horaUnidade = $('<span class="digito">').html('0')
        const minutoDezena = $('<span class="digito">').html('0')
        const minutoUnidade = $('<span class="digito">').html('0')
        const segundoDezena = $('<span class="digito">').html('0')
        const segundoUnidade = $('<span class="digito">').html('0')

        const separadorHora = $('<span class="separador">').html(':')
        const separadorMinuto = $('<span class="separador">').html(':')
        const mensagem = $('<div class="mensagem">').html(opcoesFinais.mensagem)

        $(this).addClass('temporizador')
        $(this).append(horaDezenahoraUnidadeseparadorHora,
            minutoDezenaminutoUnidadeseparadorMinuto,
            segundoDezenasegundoUnidademensagem)

        const regex = new RegExp(/(\d\d):(\d\d):(\d\d)/)
        const horarioAlvo = regex.exec(opcoesFinais.horario)
        // console.log(horarioAlvo)

        let temporizador = setInterval(() => {
            const agora = new Date()
            const alvo = new Date()
            alvo.setHours(horarioAlvo[1])
            alvo.setMinutes(horarioAlvo[2])
            alvo.setSeconds(horarioAlvo[3])

            const diferencaEmMili = alvo.getTime() - agora.getTime()
            if (diferencaEmMili >= 0) {
                const diferenca = regex.exec(new Date(diferencaEmMili).toISOString())
                console.log(diferenca)

                horaDezena.html(diferenca[1][0])
                horaUnidade.html(diferenca[1][1])
                minutoDezena.html(diferenca[2][0])
                minutoUnidade.html(diferenca[2][1])
                segundoDezena.html(diferenca[3][0])
                segundoUnidade.html(diferenca[3][1])
            } else {
                clearInterval(temporizador)
            }
        }, 1000)
        
        return this
    }
})(jQuery)

Arquivo: plugin2.html
<!DOCTYPE html>
<html>

<head>
    <meta charset='UTF-8'>
    <title>Plugin #02</title>
    <link rel='stylesheet' href='css/temporizador.css'>
    <script src='js/jquery.js'></script>
</head>

<body>
    <h1>Plugin #02 - Temporizador</h1>
    <div></div>
    <script src="js/temporizador.js"></script>
    <script>
        // ...
        $('div').temporizador({
            mensagem: 'Em breve um novo site para você',
            horario: '20:00:00'
        }).hide().fadeIn(3000)
    </script>
</body>

Arquivo: jquery.js CLIQUE AQUI para fazer o download do arquivo




07/07/2021

Plugin #01 com jQuery em HTML

Arquivo: estilo.css
@font-face {
    font-family'Oswald';
    srcurl('../fonts/Oswald-Regular.ttf'format('truetype');
}

*{
    font-family'Oswald'sans-serif;
}

html {
    height100%;
}

body {
    margin0;
    background-color#0D262D;
    color#fff;
    height100%;
}

table {
    border-collapsecollapse;
}

tr {
    border-bottomsolid 1px white;
}

td {
    font-size1.6em;
    padding10px;
}

li {
    font-size1.6em;
}

.conteudo {
    displayflex;
    flex-directioncolumn;
    align-itemscenter;
    min-height100%;
}

.exercicio div {
    font-size1.8em;
    bordersolid 5px #fff;
    padding0px 40px;
    margin10px;
}

.exercicio div:nth-of-type(1) {
    background-colordarkgoldenrod;
}

.exercicio div:nth-of-type(2) {
    background-colorcrimson;
}

.exercicio div:nth-of-type(3) {
    background-colordarkcyan;
}

.exercicio div:nth-of-type(4) {
    background-colordarkorchid;
}

.exercicio div:nth-of-type(5) {
    background-colordodgerblue;
}

.exercicio div:nth-of-type(6) {
    background-colorsalmon;
}

.exercicio .destaque {
    bordersolid 10px greenyellow;
    colorgreenyellow;
    font-weightbold;
}

Arquivo: plugin1.html
<!DOCTYPE html>
<html>

<head>
    <meta charset='UTF-8'>
    <title>Plugin #01</title>
    <link rel='stylesheet' href='css/estilo.css'>
    <script src='js/jquery.js'></script>
</head>

<body class='conteudo exercicio'>
    <h1>Plugin #01</h1>
    <div>
        {{ 1 + 2 }}
        Texto 1
        {{ 3 ** 3 }}
        Texto 2
        {{ console.log('Funcionou!') }}
        Texto 3
        {{ (function() { return 'Legal!!!' })() }}
        Texto Final
    </div>

    <script>
        //Objetivo: converter o texto acima em algo concreto
        //const $ = {nome: 'Não é o jQuery'}
        (function ($) {
            $.fn.interpretar = function (){
                const retirarChaves = s => s.substring(2s.length -2)
                const conteudo = $(this).html()
                const expressoesComChaves = conteudo.match(/\{\{.+\}\}/g)
                const expressoes = expressoesComChaves.map(retirarChaves)
                const resultados = expressoes.map(e => eval(e))

                let conteudoFinal = conteudo
                for(let i = 0i < expressoesComChaves.lengthi++){
                    conteudoFinal = conteudoFinal.replace(
                        expressoesComChaves[i], resultados[i]
                    )
                }
                $(this).html(conteudoFinal)
            }
        })(jQuery)
        $('div').interpretar()//chamando o plugin
    </script>
</body>

Arquivo: jquery.js CLIQUE AQUI para fazer o download do arquivo







06/07/2021

Animação #02 com jQuery em HTML

Arquivo: estilo.css
@font-face {
    font-family'Oswald';
    srcurl('../fonts/Oswald-Regular.ttf'format('truetype');
}

*{
    font-family'Oswald'sans-serif;
}

html {
    height100%;
}

body {
    margin0;
    background-color#0D262D;
    color#fff;
    height100%;
}

table {
    border-collapsecollapse;
}

tr {
    border-bottomsolid 1px white;
}

td {
    font-size1.6em;
    padding10px;
}

li {
    font-size1.6em;
}

.conteudo {
    displayflex;
    flex-directioncolumn;
    align-itemscenter;
    min-height100%;
}

.exercicio div {
    font-size1.8em;
    bordersolid 5px #fff;
    padding0px 40px;
    margin10px;
}

.exercicio div:nth-of-type(1) {
    background-colordarkgoldenrod;
}

.exercicio div:nth-of-type(2) {
    background-colorcrimson;
}

.exercicio div:nth-of-type(3) {
    background-colordarkcyan;
}

.exercicio div:nth-of-type(4) {
    background-colordarkorchid;
}

.exercicio div:nth-of-type(5) {
    background-colordodgerblue;
}

.exercicio div:nth-of-type(6) {
    background-colorsalmon;
}

.exercicio .destaque {
    bordersolid 10px greenyellow;
    colorgreenyellow;
    font-weightbold;
}

Arquivo: animacao2.html
<!DOCTYPE html>
<html>

<head>
    <meta charset='UTF-8'>
    <title>Animação #02</title>
    <link rel='stylesheet' href='css/estilo.css'>
    <script src='js/jquery.js'></script>
    <style>
        body {
            positionrelative;
            background-color#999;
            color#000;
        }

        div {
            positionabsolute;
            displayinline;
            bordersolid 10px #000;
            padding50px;
            font-size3em;
            background-colorcrimson;
        }
    </style>
</head>

<body>
    <div>Animar!</div>

    <script>
        //Função para alterar largura
        function alterarLargura(valorduracaocallback) {
            $('div').animate({ width: `+=${valor}` }, duracao
                , callback)
        }

        //função para mover na diagonal
        function moverDiagonal(valorduracaocallback) {
            $('div').animate({ top: `+=${valor}`left: `+=${valor}` }
                , duracaocallback)
        }

        //função de girar
        function girar(valorduracaocallback) {
            $('div').animate({ transform: `+=${valor}` }, {
                step: function (valor) {
                    $(this).css('transform'`rotate(${valor}deg)`)
                },
                duration: duracao
            }, 'linear'callback)
        }

        //chamando as funções
        alterarLargura(300100, () => {
            alterarLargura(-300'slow', () => {
                moverDiagonal(300600, () => {
                    girar(33003000)
                })
            })
        })
    </script>
</body>


Arquivo: jquery.js clique aqui para fazer o download
































01/07/2021

Animação #01 com jQuery em HTML

Arquivo: estilo.css

@font-face {
    font-family'Oswald';
    srcurl('../fonts/Oswald-Regular.ttf'format('truetype');
}

*{
    font-family'Oswald'sans-serif;
}

html {
    height100%;
}

body {
    margin0;
    background-color#0D262D;
    color#fff;
    height100%;
}

table {
    border-collapsecollapse;
}

tr {
    border-bottomsolid 1px white;
}

td {
    font-size1.6em;
    padding10px;
}

li {
    font-size1.6em;
}

.conteudo {
    displayflex;
    flex-directioncolumn;
    align-itemscenter;
    min-height100%;
}

.exercicio div {
    font-size1.8em;
    bordersolid 5px #fff;
    padding0px 40px;
    margin10px;
}

.exercicio div:nth-of-type(1) {
    background-colordarkgoldenrod;
}

.exercicio div:nth-of-type(2) {
    background-colorcrimson;
}

.exercicio div:nth-of-type(3) {
    background-colordarkcyan;
}

.exercicio div:nth-of-type(4) {
    background-colordarkorchid;
}

.exercicio div:nth-of-type(5) {
    background-colordodgerblue;
}

.exercicio div:nth-of-type(6) {
    background-colorsalmon;
}

.exercicio .destaque {
    bordersolid 10px greenyellow;
    colorgreenyellow;
    font-weightbold;
}

Arquivo: animacao1.html

<!DOCTYPE html>
<html>

<head>
    <meta charset='UTF-8'>
    <title>Animação #01</title>
    <link rel='stylesheet' href='css/estilo.css'>
    <script src='js/jquery.js'></script>
    <style>
        div {
            text-aligncenter;
        }
        button {
            font-size1.8em;
            margin10px;
        }
    </style>
</head>

<body class='conteudo exercicio'>
    <h1>Animação #01</h1>
    <button>Iniciar</button>
    <div id='animar'>Animar!</div>

    <script>        
        // tempo da animação
        $('button').click(e =>{
            const t = 450
            $('#animar').hide(t).show(t)
            //$('#animar').fadeOut(t).fadeIn(t)//se estiver exibindo vai esconder e vice verso
            $('#animar').fadeToggle(t).fadeToggle(t)
            //$('#animar').slideUp(t).slideDown(t)
            $('#animar').slideToggle(t).slideToggle(t)
        })

    </script>
</body>

Arquivo: jquery.js clique aqui para fazer o download