Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Range Slider com Máscara Monetária - Bootstrap 4</title>
- <!-- Bootstrap 4 CSS -->
- <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
- <style>
- .slider-labels {
- display: flex;
- justify-content: space-between;
- margin-top: 10px;
- }
- .slider-container {
- margin-top: 20px;
- }
- /* === range theme and appearance === */
- input[type="range"] {
- font-size: 1.5rem;
- width: 100%;
- }
- input[type="range"] {
- color: #058075;
- --thumb-height: 1.125em;
- --track-height: 0.125em;
- --track-color: rgba(0, 0, 0, 0.2);
- --brightness-hover: 120%;
- --brightness-down: 110%;
- --clip-edges: 0.125em;
- }
- @media (prefers-color-scheme: dark) {
- html {
- background-color: #000;
- }
- html::before {
- background: radial-gradient(circle at center, #101112, #000);
- }
- input[type="range"] {
- color: #f07167;
- --track-color: rgba(255, 255, 255, 0.1);
- }
- input[type="range"].win10-thumb {
- color: #3a86ff;
- }
- }
- /* === range commons === */
- input[type="range"] {
- position: relative;
- background: #fff0;
- overflow: hidden;
- }
- input[type="range"]:active {
- cursor: grabbing;
- }
- input[type="range"]:disabled {
- filter: grayscale(1);
- opacity: 0.3;
- cursor: not-allowed;
- }
- /* === WebKit specific styles === */
- input[type="range"],
- input[type="range"]::-webkit-slider-runnable-track,
- input[type="range"]::-webkit-slider-thumb {
- -webkit-appearance: none;
- transition: all ease 100ms;
- height: var(--thumb-height);
- }
- input[type="range"]::-webkit-slider-runnable-track,
- input[type="range"]::-webkit-slider-thumb {
- position: relative;
- }
- input[type="range"]::-webkit-slider-thumb {
- --thumb-radius: calc((var(--thumb-height) * 0.5) - 1px);
- --clip-top: calc((var(--thumb-height) - var(--track-height)) * 0.5 - 0.5px);
- --clip-bottom: calc(var(--thumb-height) - var(--clip-top));
- --clip-further: calc(100% + 1px);
- --box-fill: calc(-100vmax - var(--thumb-width, var(--thumb-height))) 0 0 100vmax currentColor;
- width: var(--thumb-width, var(--thumb-height));
- background: linear-gradient(currentColor 0 0) scroll no-repeat left center / 50% calc(var(--track-height) + 1px);
- background-color: currentColor;
- box-shadow: var(--box-fill);
- border-radius: var(--thumb-width, var(--thumb-height));
- filter: brightness(100%);
- clip-path: polygon(100% -1px,
- var(--clip-edges) -1px,
- 0 var(--clip-top),
- -100vmax var(--clip-top),
- -100vmax var(--clip-bottom),
- 0 var(--clip-bottom),
- var(--clip-edges) 100%,
- var(--clip-further) var(--clip-further));
- }
- input[type="range"]:hover::-webkit-slider-thumb {
- filter: brightness(var(--brightness-hover));
- cursor: grab;
- }
- input[type="range"]:active::-webkit-slider-thumb {
- filter: brightness(var(--brightness-down));
- cursor: grabbing;
- }
- input[type="range"]::-webkit-slider-runnable-track {
- background: linear-gradient(var(--track-color) 0 0) scroll no-repeat center / 100% calc(var(--track-height) + 1px);
- }
- input[type="range"]:disabled::-webkit-slider-thumb {
- cursor: not-allowed;
- }
- /* === Firefox specific styles === */
- input[type="range"],
- input[type="range"]::-moz-range-track,
- input[type="range"]::-moz-range-thumb {
- appearance: none;
- transition: all ease 100ms;
- height: var(--thumb-height);
- }
- input[type="range"]::-moz-range-track,
- input[type="range"]::-moz-range-thumb,
- input[type="range"]::-moz-range-progress {
- background: #fff0;
- }
- input[type="range"]::-moz-range-thumb {
- background: currentColor;
- border: 0;
- width: var(--thumb-width, var(--thumb-height));
- border-radius: var(--thumb-width, var(--thumb-height));
- cursor: grab;
- }
- input[type="range"]:active::-moz-range-thumb {
- cursor: grabbing;
- }
- input[type="range"]::-moz-range-track {
- width: 100%;
- background: var(--track-color);
- }
- input[type="range"]::-moz-range-progress {
- appearance: none;
- background: currentColor;
- transition-delay: 30ms;
- }
- input[type="range"]::-moz-range-track,
- input[type="range"]::-moz-range-progress {
- height: calc(var(--track-height) + 1px);
- border-radius: var(--track-height);
- }
- input[type="range"]::-moz-range-thumb,
- input[type="range"]::-moz-range-progress {
- filter: brightness(100%);
- }
- input[type="range"]:hover::-moz-range-thumb,
- input[type="range"]:hover::-moz-range-progress {
- filter: brightness(var(--brightness-hover));
- }
- input[type="range"]:active::-moz-range-thumb,
- input[type="range"]:active::-moz-range-progress {
- filter: brightness(var(--brightness-down));
- }
- input[type="range"]:disabled::-moz-range-thumb {
- cursor: not-allowed;
- }
- </style>
- </head>
- <body>
- <form id="formSimulacao" autocomplete="off">
- <!-- Step 1 -->
- <div class="step active" id="step1">
- <div class="container">
- <div class="row">
- <div class="container h-100">
- <div class="row d-flex justify-content-center align-items-center h-100">
- <div class="col-lg-12 col-xl-11">
- <div class="card text-black" style="border-radius: 25px;">
- <div class="card-body p-md-5">
- <div class="row justify-content-center">
- <div class="form-group">
- <button id="voltar" name="voltar" class="btn btn-primary" type="button"
- onclick="portletHome()">Voltar</button>
- </div>
- </div>
- <div class="row justify-content-center">
- <h3>Escolha a forma desejada para simular, pelo valor da carta de
- crédito ou da parcela.</h3>
- </div>
- <div class="row justify-content-center">
- <div
- class="col-md-10 col-lg-6 col-xl-7 d-flex align-items-center order-1 order-lg-1">
- <img src="https://mdbcdn.b-cdn.net/img/Photos/new-templates/bootstrap-registration/draw1.webp"
- class="img-fluid" alt="Sample image">
- </div>
- <div class="col-md-10 col-lg-6 col-xl-5 order-2 order-lg-2">
- <div class="form-group">
- <div style='display: none;' id="radioDivSegmento" class="col-md-6">
- <input type="radio" id="imoveis" name="segmento" value="IMOVEIS"
- checked>
- </div>
- </div>
- <div class="form-group">
- <div id="radioDiv">
- <input type="radio" id="credito" name="tipo" value="CREDITO"
- checked>
- <label for="credito">Valor do crédito</label>
- <input type="radio" id="parcela" name="tipo" value="PARCELA">
- <label for="parcela">Valor da parcela</label>
- </div>
- </div>
- <!-- Campo de input para mostrar o valor com máscara monetária -->
- <div class="form-group">
- <input type="text" class="form-control" id="valorBem"
- value="300000">
- </div>
- <!-- Range Slider logo abaixo do input -->
- <div class="slider-container">
- <input type="range" id="slider" name="slider" min="0" max="600000" step="1000" value="300000">
- </div>
- <!-- Rótulos de mínimo e máximo para o slider -->
- <div class="slider-labels">
- <span id="min-label">R$ 0</span>
- <span id="max-label">R$ 600.000,00</span>
- </div>
- <p>Digite ou arraste o seletor acima para ajustar o valor.</p>
- </div>
- </div>
- <div class="row justify-content-center">
- <div class="form-group">
- <button type="submit" id="verOpcoes" name="verOpcoes"
- class="btn btn-primary">Ver opções</button>
- </div>
- <div class="d-flex justify-content-center mx-4 mb-3 mb-lg-4"
- id="divMensagens">
- <div style='display: none;' id="mensagem-erro"
- class="alert alert-danger">
- <svg width="24" height="24" viewBox="0 0 24 24" fill="none"
- xmlns="http://www.w3.org/2000/svg">
- <path
- d="M12 20C16.4187 20 20 16.4187 20 12C20 7.58125 16.4187 4 12 4C7.58125 4 4 7.58125 4 12C4 16.4187 7.58125 20 12 20ZM12 8C12.4156 8 12.75 8.33437 12.75 8.75V12.25C12.75 12.6656 12.4156 13 12 13C11.5844 13 11.25 12.6656 11.25 12.25V8.75C11.25 8.33437 11.5844 8 12 8ZM13 15C13 15.5531 12.5531 16 12 16C11.4469 16 11 15.5531 11 15C11 14.4469 11.4469 14 12 14C12.5531 14 13 14.4469 13 15Z"
- fill="#DA1414"></path>
- </svg>
- <span class="message"><strong>Ocorreu um erro ao realizar a
- Simulação.</span>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div class="row">
- <div class="container h-100">
- <div class="row d-flex justify-content-center align-items-center h-100">
- <div class="col-lg-12 col-xl-11">
- <div id="resultados" class="mt-4 mb-5">
- <table class="table table-striped">
- <thead>
- <tr>
- <th>Valor</th>
- <th>Parcelas(1 a 6)¹</th>
- <th>Demais Parcelas²</th>
- <th>Prazo</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>
- R$ 300.000,00
- </td>
- <td>
- R$ 3.423,00
- </td>
- <td>
- R$ 2.460,03
- </td>
- <td>
- <div class="custom-control custom-switch">
- <input type="checkbox" class="custom-control-input"
- id="switchPrazo1" name="switchPrazo" checked>
- <label class="custom-control-label"
- for="switchPrazo1">150</label>
- </div>
- </td>
- </tr>
- <tr>
- <td>
- R$ 300.000,00
- </td>
- <td>
- R$ 3.048,01
- </td>
- <td>
- R$ 2.078,37
- </td>
- <td>
- <div class="custom-control custom-switch">
- <input type="checkbox" class="custom-control-input"
- id="switchPrazo2" name="switchPrazo">
- <label class="custom-control-label"
- for="switchPrazo2">180</label>
- </div>
- </td>
- </tr>
- <tr>
- <td>
- R$ 300.000,00
- </td>
- <td>
- R$ 2.860,50
- </td>
- <td>
- R$ 1.887,53
- </td>
- <td>
- <div class="custom-control custom-switch">
- <input type="checkbox" class="custom-control-input"
- id="switchPrazo3" name="switchPrazo">
- <label class="custom-control-label"
- for="switchPrazo3">200</label>
- </div>
- </td>
- </tr>
- <tr>
- <td>
- R$ 300.000,00
- </td>
- <td>
- R$ 2.579,25
- </td>
- <td>
- R$ 1.601,28
- </td>
- <td>
- <div class="custom-control custom-switch">
- <input type="checkbox" class="custom-control-input"
- id="switchPrazo4" name="switchPrazo">
- <label class="custom-control-label"
- for="switchPrazo4">240</label>
- </div>
- </td>
- </tr>
- </tbody>
- </table>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </form>
- <!-- jQuery e jQuery Mask Plugin -->
- <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
- <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.16/jquery.mask.min.js"></script>
- <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js"></script>
- <script type="text/javascript">
- let $portletValorMinimoValorCredito = 0;
- let $portletValorMaximoValorCredito = 600000;
- let $portletValorInicialValorCredito = $portletValorMaximoValorCredito / 2;
- let $portletValorMinimoValorParcela = 0;
- let $portletValorMaximoValorParcela = 6000;
- let $portletValorInicialValorParcela = $portletValorMaximoValorParcela / 2;
- // Aplicar a máscara no campo de input ao carregar a página
- $('#valorBem').val(formatCurrency($('#valorBem').val()));
- // Definir o valor inicial formatado corretamente
- let valorInicial = 0;
- if (typeof $portletValorMaximoValorCredito != "undefined") {
- valorInicial = $portletValorMaximoValorCredito / 2;
- }
- $("#valorBem").val(formatCurrency(valorInicial));
- $("#slider").val(valorInicial);
- // Adiciona um evento onchange aos radio button
- $('input[name="tipo"]').change(function () {
- let valorSelecionado = $('input[name="tipo"]:checked').val();
- if (valorSelecionado === "CREDITO") {
- $('#valorBem').val(formatCurrency($portletValorInicialValorCredito));
- $("#max-label").text("R$ " + formatCurrency($portletValorMaximoValorCredito) + ",00");
- $('#slider').attr('max', $portletValorMaximoValorCredito);
- $('#slider').val($portletValorInicialValorCredito);
- } else if (valorSelecionado === "PARCELA") {
- $('#valorBem').val(formatCurrency($portletValorInicialValorParcela));
- $("#max-label").text("R$ " + formatCurrency($portletValorMaximoValorParcela) + ",00");
- $('#slider').attr('max', $portletValorMaximoValorParcela);
- $('#slider').val($portletValorInicialValorParcela);
- }
- });
- // Logica do Slider
- // Atualizar o valor do input conforme o slider muda
- $("#slider").on('input', function () {
- let valorSlider = $(this).val();
- $('#valorBem').val(formatCurrency(valorSlider));
- });
- $('#valorBem').on('keypress', function (e) {
- // Permitir apenas números
- if (e.which < 48 || e.which > 57) {
- e.preventDefault();
- }
- });
- // Quando o usuário digitar manualmente, manter o "R$" no campo
- $("#valorBem").on('blur', function () {
- let valorBem = limparNumero($(this).val());
- if (valorBem) {
- let valorSelecionado = $('input[name="tipo"]:checked').val();
- if (valorSelecionado === "CREDITO") {
- if (valorBem > $portletValorMaximoValorCredito) {
- let valorFormatado = formatCurrency($portletValorMaximoValorCredito);
- $('#valorBem').val(valorFormatado);
- $("#slider").val(limparNumero(valorFormatado)); // Atualizar o slider com o valor correto
- return;
- }
- } else if (valorSelecionado === "PARCELA") {
- if (valorBem > $portletValorMaximoValorParcela) {
- let valorFormatadoParcela = formatCurrency($portletValorMaximoValorParcela);
- $('#valorBem').val(valorFormatadoParcela);
- $("#slider").val(limparNumero(valorFormatadoParcela)); // Atualizar o slider com o valor correto
- return;
- }
- }
- if ($(this).val() === "") {
- $(this).val(formatCurrency($("#slider").val())); // Aplicar formatação correta
- } else {
- $(this).val(formatCurrency(valorBem)); // Aplicar formatação correta
- $("#slider").val(valorBem); // Atualizar o slider com o valor correto
- }
- } else {
- $("#valorBem").val(formatCurrency(valorInicial));
- $("#slider").val(valorInicial);
- }
- });
- function formatCurrency(value) {
- return parseInt(value).toLocaleString('pt-BR');
- }
- function limparNumero(valor) {
- return valor.replace(/[^\d]/g, '');
- }
- // // Adiciona um evento de clique para os checkboxes da tabela step 2
- // $('input[name="switchPrazo"]').change(function() {
- // console.log("evento checkbox");
- // });
- document.querySelectorAll('input[name="switchPrazo"]').forEach(function (element) {
- element.addEventListener('change', function () {
- // Aqui você adiciona o código que deseja executar quando o switch for alterado
- console.log("Mudança detectada no switch:", this.id);
- // Desmarca todos os outros checkboxes e remove a classe 'font-weight-bold' de suas linhas
- $("input[name='switchPrazo']").not(this).prop('checked', false).closest('tr').removeClass('font-weight-bold');
- // Se o checkbox atual estiver marcado, adiciona a classe 'font-weight-bold' à linha correspondente
- if ($(this).prop('checked')) {
- $(this).closest('tr').addClass('font-weight-bold');
- } else {
- $(this).closest('tr').removeClass('font-weight-bold');
- }
- });
- });
- </script>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement