html – Mudar src da imagem com javascript

Estou tentando fazer com que a imagem mude cada vez que eu clique no botão, de modo que quando eu clico na image1 ele vire image2 e quando clique nao image2 ela volte a ser image1

<script>
function changeImage(){
  var image = document.getElementById("image");
  if(image.src = "image1.png"){
      image.src = "image2.png";
  }
  else if(image.src = "image2.png"){
      image.src = "image1.png";
  }
}
<img id="image" src="image1.png" width="490" height="364">

<button onclick="changeImage()">Mudar image</button>

só que ele só consegue virar image2, depois disso não volta a ser image1

javascript – How to add div id/class names dynamically to jquery

I am having the below code to capture the div id. I want to capture the first child div of this div. How can i do that in jquery? Pretty new to this so please be a bit kind 🙂

$('.elementor-tab-title').click(function(e) {

var id1= $(this).next("div").attr('id');
var id2=$("#"+id:first-child").attr('id'); // I know this is wrong but i am trying to capture the first child of div starting with id stored in variable id1.
  
alert("Hi "+id1);
alert("Hello "+id2); }

javascript – How can I make the quickview open in mobile?

jQuery(document).ready(function($){
    //final width --> this is the quick view image slider width
    //maxQuickWidth --> this is the max-width of the quick-view panel
    var sliderFinalWidth = 400,
        maxQuickWidth = 900;

    //open the quick view panel
    $('.cd-trigger').on('click', function(event){
        var selectedImage = $(this).parent('.cd-item').children('img'),
            slectedImageUrl = selectedImage.attr('src');

        var href = $(this).attr('href');
        
        $('body').addClass('overlay-layer');
        animateQuickView(selectedImage, sliderFinalWidth, maxQuickWidth, 'open', href);

        //update the visible slider image in the quick view panel
        //you don't need to implement/use the updateQuickView if retrieving the quick view data with ajax
        updateQuickView(slectedImageUrl);
    });

    //close the quick view panel
    $('body').on('click', function(event){
        if( $(event.target).is('.cd-close') "https://codereview.stackexchange.com/" $(event.target).is('body.overlay-layer')) {
            closeQuickView( sliderFinalWidth, maxQuickWidth);
        }
    });
    $(document).keyup(function(event){
        //check if user has pressed 'Esc'
        if(event.which=='27'){
            closeQuickView( sliderFinalWidth, maxQuickWidth);
        }
    });

    //quick view slider implementation
    $('.cd-quick-view').on('click', '.cd-slider-navigation a', function(){
        updateSlider($(this));
    });

    //center quick-view on window resize
    $(window).on('resize', function(){
        if($('.cd-quick-view').hasClass('is-visible')){
            window.requestAnimationFrame(resizeQuickView);
        }
    });

    function updateSlider(navigation) {
        var sliderConatiner = navigation.parents('.cd-slider-wrapper').find('.cd-slider'),
            activeSlider = sliderConatiner.children('.selected').removeClass('selected');
        if ( navigation.hasClass('cd-next') ) {
            ( !activeSlider.is(':last-child') ) ? activeSlider.next().addClass('selected') : sliderConatiner.children('li').eq(0).addClass('selected'); 
        } else {
            ( !activeSlider.is(':first-child') ) ? activeSlider.prev().addClass('selected') : sliderConatiner.children('li').last().addClass('selected');
        } 
    }

    function updateQuickView(url) {
        $('.cd-quick-view .cd-slider li').removeClass('selected').find('img(src="https://codereview.stackexchange.com/"+ url +"https://codereview.stackexchange.com/")').parent('li').addClass('selected');
    }

    function resizeQuickView() {
        var quickViewLeft = ($(window).width() - $('.cd-quick-view').width())/2,
            quickViewTop = ($(window).height() - $('.cd-quick-view').height())/2;
        $('.cd-quick-view').css({
            "top": quickViewTop,
            "left": quickViewLeft,
        });
    } 

    function closeQuickView(finalWidth, maxQuickWidth) {
        var close = $('.cd-close'),
            activeSliderUrl = close.siblings('.cd-slider-wrapper').find('.selected img').attr('src'),
            selectedImage = $('.empty-box').find('img');
        //update the image in the gallery
        if( !$('.cd-quick-view').hasClass('velocity-animating') && $('.cd-quick-view').hasClass('add-content')) {
            selectedImage.attr('src', activeSliderUrl);
            animateQuickView(selectedImage, finalWidth, maxQuickWidth, 'close');
        } else {
            closeNoAnimation(selectedImage, finalWidth, maxQuickWidth);
        }
    }

    function animateQuickView(image, finalWidth, maxQuickWidth, animationType, href) {
        //store some image data (width, top position, ...)
        //store window data to calculate quick view panel position
        var parentListItem = image.parent('.cd-item'),
            topSelected = image.offset().top - $(window).scrollTop(),
            leftSelected = image.offset().left,
            widthSelected = image.width(),
            heightSelected = image.height(),
            windowWidth = $(window).width(),
            windowHeight = $(window).height(),
            finalLeft = (windowWidth - finalWidth)/2,
            finalHeight = finalWidth * heightSelected/widthSelected,
            finalTop = (windowHeight - finalHeight)/2,
            quickViewWidth = ( windowWidth * .8 < maxQuickWidth ) ? windowWidth * .8 : maxQuickWidth ,
            quickViewLeft = (windowWidth - quickViewWidth)/2;

        if( animationType == 'open') {
            //hide the image in the gallery
            parentListItem.addClass('empty-box');
            //place the quick view over the image gallery and give it the dimension of the gallery image
            $(href).css({
                "top": topSelected,
                "left": leftSelected,
                "width": widthSelected,
            }).velocity({
                //animate the quick view: animate its width and center it in the viewport
                //during this animation, only the slider image is visible
                'top': finalTop+ 'px',
                'left': finalLeft+'px',
                'width': finalWidth+'px',
            }, 1000, ( 400, 20 ), function(){
                //animate the quick view: animate its width to the final value
                $(href).addClass('animate-width').velocity({
                    'left': quickViewLeft+'px',
                    'width': quickViewWidth+'px',
                }, 300, 'ease' ,function(){
                    //show quick view content
                    $(href).addClass('add-content');
                });
            }).addClass('is-visible');
        } else {
            //close the quick view reverting the animation
            $('.cd-quick-view').removeClass('add-content').velocity({
                'top': finalTop+ 'px',
                'left': finalLeft+'px',
                'width': finalWidth+'px',
            }, 300, 'ease', function(){
                $('body').removeClass('overlay-layer');
                $('.cd-quick-view').removeClass('animate-width').velocity({
                    "top": topSelected,
                    "left": leftSelected,
                    "width": widthSelected,
                }, 500, 'ease', function(){
                    $('.cd-quick-view').removeClass('is-visible');
                    parentListItem.removeClass('empty-box');
                });
            });
        }
    }
    function closeNoAnimation(image, finalWidth, maxQuickWidth) {
        var parentListItem = image.parent('.cd-item'),
            topSelected = image.offset().top - $(window).scrollTop(),
            leftSelected = image.offset().left,
            widthSelected = image.width();

        $('body').removeClass('overlay-layer');
        parentListItem.removeClass('empty-box');
        $('.cd-quick-view').velocity("stop").removeClass('add-content animate-width is-visible').css({
            "top": topSelected,
            "left": leftSelected,
            "width": widthSelected,
        });
    }
});
*, *::after, *::before {
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
}

*::after, *::before {
  content: "https://codereview.stackexchange.com/";
}

body {
  font-size: 100%;
  font-family: "PT Sans", sans-serif;
  color: #3e585f;
  background-color: #ffffff;
}
body::after {
  /* dark overlay layer - visible when we fire .cd-quick-view */
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(71, 55, 78, 0.8);
  visibility: hidden;
  opacity: 0;
  -webkit-transition: opacity .3s 0s, visibility 0s .3s;
  -moz-transition: opacity .3s 0s, visibility 0s .3s;
  transition: opacity .3s 0s, visibility 0s .3s;
}
@media only screen and (min-width: 1024px) {
  body.overlay-layer::after {
    visibility: visible;
    opacity: 1;
    -webkit-transition: opacity .3s 0s, visibility 0s 0s;
    -moz-transition: opacity .3s 0s, visibility 0s 0s;
    transition: opacity .3s 0s, visibility 0s 0s;
  }
}

a {
  color: #f82f53;
  text-decoration: none;
}

img {
  max-width: 100%;
}

/* -Modules - reusable parts of our design----- */
.cd-container {
  /* this class is used to give a max-width to the element it is applied to, and center it horizontally when it reaches that max-width */
  width: 90%;
  max-width: 1170px;
  margin: 0 auto;
}
.cd-container:after {
  content: "https://codereview.stackexchange.com/";
  display: table;
  clear: both;
}

/* ---Main components --- */
html, body {
  height: 100%;
}

header {
  position: relative;
  height: 160px;
  line-height: 170px;
  text-align: center;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
header h1 {
  color: #000000;
  font-size: 20px;
  font-size: 1.25rem;
}
@media only screen and (min-width: 768px) {
  header {
    line-height: 180px;
  }
  header h1 {
    font-size: 26px;
    font-size: 1.625rem;
  }
}
@media only screen and (min-width: 1024px) {
  header {
    line-height: 220px;
  }
}

.cd-items {
  padding: 1em 0;
}
@media only screen and (min-width: 768px) {
  .cd-items {
    padding: 2em 0 0;
  }
}
@media only screen and (min-width: 1024px) {
  .cd-items {
    padding: 4em 0 0;
  }
}

.cd-item {
  position: relative;
  margin: 0 0 1em;
}
.cd-item > img {
  display: block;
  width: 100%;
}
@media only screen and (min-width: 768px) {
  .cd-item {
    width: 48%;
    float: left;
    margin: 0 4% 2em 0;
  }
  .cd-item:nth-child(2n) {
    margin-right: 0;
  }
}
@media only screen and (min-width: 1024px) {
  .cd-item {
    width: 22%;
    float: left;
    margin: 0 4% 2.8em 0;
  }
  .cd-item:nth-child(2n) {
    margin-right: 4%;
  }
  .cd-item:nth-child(4n) {
    margin-right: 0;
  }
  .cd-item.empty-box::after {
    /* box visible as placeholder when the .cd-quick-view zooms in */
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #392c3f;
  }
}

.cd-trigger {
  position: absolute;
  height: 50px;
  line-height: 50px;
  width: 100%;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.1);
  text-align: center;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #ffffff;
  opacity: 0;
  visibility: hidden;
  -webkit-transition: opacity 0.2s, background-color 0.2s;
  -moz-transition: opacity 0.2s, background-color 0.2s;
  transition: opacity 0.2s, background-color 0.2s;
}
.no-touch .cd-trigger:hover {
  background: rgba(0, 0, 0, 0.2);
}
@media only screen and (min-width: 1024px) {
  .cd-trigger {
    /* always visible on small devices */
    visibility: visible;
    opacity: 1;
  }
}
@media only screen and (min-width: 1170px) {
  .cd-trigger {
    /* only visible on hover on big devices */
    opacity: 0;
  }
}

@media only screen and (min-width: 1170px) {
  .no-touch .cd-item:hover .cd-trigger {
    opacity: 1;
  }

  .touch .cd-item .cd-trigger {
    opacity: 1;
  }
}
.cd-quick-view {
  /* quick view non available on small devices */
  display: none;
}
@media only screen and (min-width: 1024px) {
  .cd-quick-view {
    display: block;
    position: fixed;
    max-width: 900px;
    visibility: hidden;
    /* Force Hardware Acceleration in WebKit */
    -webkit-transform: translateZ(0);
    -moz-transform: translateZ(0);
    -ms-transform: translateZ(0);
    -o-transform: translateZ(0);
    transform: translateZ(0);
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
    will-change: left, top, width;
    z-index: 1;
  }
  .cd-quick-view:after {
    content: "https://codereview.stackexchange.com/";
    display: table;
    clear: both;
  }
  .cd-quick-view.is-visible {
    /* class added when user clicks on .cd-trigger */
    visibility: visible;
  }
  .cd-quick-view.animate-width {
    /* class added at the end of the first zoom-in animation */
    background-color: #ffffff;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.2);
    -webkit-transition: box-shadow 0.3s;
    -moz-transition: box-shadow 0.3s;
    transition: box-shadow 0.3s;
  }
}

.cd-slider-wrapper {
  position: relative;
  display: inline-block;
  float: left;
}
.cd-slider-wrapper:after {
  content: "https://codereview.stackexchange.com/";
  display: table;
  clear: both;
}

.cd-slider {
  float: left;
}
.cd-slider li {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
}
.cd-slider li img {
  display: block;
  width: 100%;
  max-width: 400px;
}
.cd-slider li.selected {
  position: relative;
  z-index: 3;
}
.add-content .cd-slider {
  margin-right: 3em;
}

.cd-slider-navigation {
  opacity: 0;
}
.add-content .cd-slider-navigation {
  opacity: 1;
}

.cd-slider-navigation li {
  position: absolute;
  top: 50%;
  bottom: auto;
  -webkit-transform: translateY(-50%);
  -moz-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  -o-transform: translateY(-50%);
  transform: translateY(-50%);
  z-index: 3;
}
.cd-slider-navigation li:first-child {
  left: 0;
}
.cd-slider-navigation li:last-child {
  /* equal to the .cd-slider-wrapper margin-right */
  right: 3em;
}
.cd-slider-navigation li a {
  display: block;
  width: 40px;
  height: 50px;
  overflow: hidden;
  text-indent: 100%;
  white-space: nowrap;
  opacity: 0;
  /* Force Hardware Acceleration in WebKit */
  -webkit-transform: translateZ(0);
  -moz-transform: translateZ(0);
  -ms-transform: translateZ(0);
  -o-transform: translateZ(0);
  transform: translateZ(0);
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transition: opacity 0.2s, background 0.2s;
  -moz-transition: opacity 0.2s, background 0.2s;
  transition: opacity 0.2s, background 0.2s;
}
.cd-slider-navigation li a::before, .cd-slider-navigation li a::after {
  /* create arrows in CSS */
  position: absolute;
  top: 18px;
  left: 14px;
  display: inline-block;
  background: #ffffff;
  height: 3px;
  width: 12px;
}
.cd-slider-navigation li a::before {
  -webkit-transform: rotate(45deg);
  -moz-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  -o-transform: rotate(45deg);
  transform: rotate(45deg);
}
.cd-slider-navigation li a::after {
  -webkit-transform: translateY(7px) rotate(-45deg);
  -moz-transform: translateY(7px) rotate(-45deg);
  -ms-transform: translateY(7px) rotate(-45deg);
  -o-transform: translateY(7px) rotate(-45deg);
  transform: translateY(7px) rotate(-45deg);
}
.add-content .cd-slider-navigation li a {
  opacity: .2;
}
.no-touch .cd-slider-navigation li a:hover {
  background: rgba(71, 55, 78, 0.8);
  opacity: 1;
}
.touch .cd-slider-navigation li a {
  opacity: 1;
}
.cd-slider-navigation li:first-child a::before {
  -webkit-transform: rotate(-45deg);
  -moz-transform: rotate(-45deg);
  -ms-transform: rotate(-45deg);
  -o-transform: rotate(-45deg);
  transform: rotate(-45deg);
}
.cd-slider-navigation li:first-child a::after {
  -webkit-transform: translateY(7px) rotate(45deg);
  -moz-transform: translateY(7px) rotate(45deg);
  -ms-transform: translateY(7px) rotate(45deg);
  -o-transform: translateY(7px) rotate(45deg);
  transform: translateY(7px) rotate(45deg);
}

.cd-item-info {
  position: absolute;
  padding: 3em 3em 3em 0;
  visibility: hidden;
  opacity: 0;
  -webkit-transition: opacity .3s, visibility 0s;
  -moz-transition: opacity .3s, visibility 0s;
  transition: opacity .3s, visibility 0s;
}
.cd-item-info h2 {
  font-size: 28px;
  font-size: 1.75rem;
}
.cd-item-info p {
  line-height: 1.6;
  margin: 1em 0;
  color: #67919c;
}
.cd-item-info .cd-item-action li {
  display: inline-block;
  margin-right: 1em;
}
.cd-item-info .cd-item-action li:first-child {
  margin-left: -4px;
}
.cd-item-info .add-to-cart {
  -webkit-appearance: none;
  -moz-appearance: none;
  -ms-appearance: none;
  -o-appearance: none;
  appearance: none;
  border-radius: 0.25em;
  border: none;
  padding: .6em 1.2em;
  background-color: #f82f53;
  color: #ffffff;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-family: "PT Sans", sans-serif;
  font-size: 16px;
  font-size: 1rem;
  cursor: pointer;
}
.add-content .cd-item-info {
  /* class added at the end of the width animation, used to show the content */
  position: relative;
  visibility: visible;
  opacity: 1;
}
.add-content .cd-item-info h2 {
  -webkit-animation: cd-slide-in 0.3s;
  -moz-animation: cd-slide-in 0.3s;
  animation: cd-slide-in 0.3s;
}
.add-content .cd-item-info p {
  -webkit-animation: cd-slide-in 0.4s;
  -moz-animation: cd-slide-in 0.4s;
  animation: cd-slide-in 0.4s;
}
.add-content .cd-item-info .cd-item-action {
  -webkit-animation: cd-slide-in 0.5s;
  -moz-animation: cd-slide-in 0.5s;
  animation: cd-slide-in 0.5s;
}

@-webkit-keyframes cd-slide-in {
  0% {
    -webkit-transform: translate3d(-40px, 0, 0);
  }
  100% {
    -webkit-transform: translate3d(0, 0, 0);
  }
}
@-moz-keyframes cd-slide-in {
  0% {
    -moz-transform: translate3d(-40px, 0, 0);
  }
  100% {
    -moz-transform: translate3d(0, 0, 0);
  }
}
@keyframes cd-slide-in {
  0% {
    -webkit-transform: translate3d(-40px, 0, 0);
    -moz-transform: translate3d(-40px, 0, 0);
    -ms-transform: translate3d(-40px, 0, 0);
    -o-transform: translate3d(-40px, 0, 0);
    transform: translate3d(-40px, 0, 0);
  }
  100% {
    -webkit-transform: translate3d(0, 0, 0);
    -moz-transform: translate3d(0, 0, 0);
    -ms-transform: translate3d(0, 0, 0);
    -o-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
  }
}
.cd-close {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-block;
  width: 30px;
  height: 30px;
  /* image replacement */
  overflow: hidden;
  text-indent: 100%;
  white-space: nowrap;
  visibility: hidden;
  -webkit-transform: scale(0);
  -moz-transform: scale(0);
  -ms-transform: scale(0);
  -o-transform: scale(0);
  transform: scale(0);
  -webkit-transition: -webkit-transform .3s 0s, visibility 0s .3s;
  -moz-transition: -moz-transform .3s 0s, visibility 0s .3s;
  transition: transform .3s 0s, visibility 0s .3s;
}
.cd-close::before, .cd-close::after {
  /* close icon in css */
  position: absolute;
  top: 12px;
  left: 5px;
  display: inline-block;
  height: 4px;
  width: 20px;
  background: #47374e;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
}
.cd-close::before {
  -webkit-transform: rotate(45deg);
  -moz-transform: rotate(45deg);
  -ms-transform: rotate(45deg);
  -o-transform: rotate(45deg);
  transform: rotate(45deg);
}
.cd-close::after {
  -webkit-transform: rotate(135deg);
  -moz-transform: rotate(135deg);
  -ms-transform: rotate(135deg);
  -o-transform: rotate(135deg);
  transform: rotate(135deg);
}
.no-touch .cd-close:hover {
  -webkit-transform: scale(1.2);
  -moz-transform: scale(1.2);
  -ms-transform: scale(1.2);
  -o-transform: scale(1.2);
  transform: scale(1.2);
}
.add-content .cd-close {
  visibility: visible;
  -webkit-transform: scale(1);
  -moz-transform: scale(1);
  -ms-transform: scale(1);
  -o-transform: scale(1);
  transform: scale(1);
  -webkit-transition: -webkit-transform .3s 0s, visibility 0s 0s;
  -moz-transition: -moz-transform .3s 0s, visibility 0s 0s;
  transition: transform .3s 0s, visibility 0s 0s;
}
<!doctype html>
<html lang="en" class="no-js">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link href='http://fonts.googleapis.com/css?family=PT+Sans:400,700' rel='stylesheet' type='text/css'>

    <link rel="stylesheet" href="css/reset.css"> <!-- CSS reset -->
    <link rel="stylesheet" href="css/style.css"> <!-- Resource style -->
    <script src="https://codereview.stackexchange.com/js/modernizr.js"></script> <!-- Modernizr -->
    
    <title>Product Quick View | CodyHouse</title>
</head>
<body>
    <header>
        <h1>Product Quick View</h1>
    </header>
    
    <ul class="cd-items cd-container">
        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#first-item" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#second-item" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#third-item" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#fourth-item" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#0" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#0" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#0" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#0" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#0" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#0" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#0" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->

        <li class="cd-item">
            <img src="img/item-1.jpg" alt="Item Preview">
            <a href="#0" class="cd-trigger">Quick View</a>
        </li> <!-- cd-item -->
    </ul> <!-- cd-items -->

    <div id="first-item" class="cd-quick-view">
        <div class="cd-slider-wrapper">
            <ul class="cd-slider">
                <li class="selected"><img src="img/item-1.jpg" alt="Product 1"></li>
                <li><img src="img/item-2.jpg" alt="Product 2"></li>
                <li><img src="img/item-3.jpg" alt="Product 3"></li>
            </ul> <!-- cd-slider -->

            <ul class="cd-slider-navigation">
                <li><a class="cd-next" href="#0">Prev</a></li>
                <li><a class="cd-prev" href="#0">Next</a></li>
            </ul> <!-- cd-slider-navigation -->
        </div> <!-- cd-slider-wrapper -->

        <div class="cd-item-info">
            <h2>First Item</h2>
            <p>Lorem ipsum dolor </p>

            <ul class="cd-item-action">
                <li><button class="add-to-cart">Add to cart</button></li>                   
                <li><a href="#0">Learn more</a></li>    
            </ul> <!-- cd-item-action -->
        </div> <!-- cd-item-info -->
        <a href="#0" class="cd-close">Close</a>
    </div> <!-- cd-quick-view -->
    <div id="second-item" class="cd-quick-view">
        <div class="cd-slider-wrapper">
            <ul class="cd-slider">
                <li class="selected"><img src="img/item-1.jpg" alt="Product 1"></li>
                <li><img src="img/item-2.jpg" alt="Product 2"></li>
                <li><img src="img/item-3.jpg" alt="Product 3"></li>
            </ul> <!-- cd-slider -->

            <ul class="cd-slider-navigation">
                <li><a class="cd-next" href="#0">Prev</a></li>
                <li><a class="cd-prev" href="#0">Next</a></li>
            </ul> <!-- cd-slider-navigation -->
        </div> <!-- cd-slider-wrapper -->

        <div class="cd-item-info">
            <h2>Second Item</h2>
            <p>Lorem ipsum dolor</p>

            <ul class="cd-item-action">
                <li><button class="add-to-cart">Add to cart</button></li>                   
                <li><a href="#0">Learn more</a></li>    
            </ul> <!-- cd-item-action -->
        </div> <!-- cd-item-info -->
        <a href="#0" class="cd-close">Close</a>
    </div> <!-- cd-quick-view -->
    <div id="third-item" class="cd-quick-view">
        <div class="cd-slider-wrapper">
            <ul class="cd-slider">
                <li class="selected"><img src="img/item-1.jpg" alt="Product 1"></li>
                <li><img src="img/item-2.jpg" alt="Product 2"></li>
                <li><img src="img/item-3.jpg" alt="Product 3"></li>
            </ul> <!-- cd-slider -->

            <ul class="cd-slider-navigation">
                <li><a class="cd-next" href="#0">Prev</a></li>
                <li><a class="cd-prev" href="#0">Next</a></li>
            </ul> <!-- cd-slider-navigation -->
        </div> <!-- cd-slider-wrapper -->

        <div class="cd-item-info">
            <h2>Third Item</h2>
            <p>Lorem ipsum .</p>

            <ul class="cd-item-action">
                <li><button class="add-to-cart">Add to cart</button></li>                   
                <li><a href="#0">Learn more</a></li>    
            </ul> <!-- cd-item-action -->
        </div> <!-- cd-item-info -->
        <a href="#0" class="cd-close">Close</a>
    </div> <!-- cd-quick-view -->
    <div id="fourth-item" class="cd-quick-view">
        <div class="cd-slider-wrapper">
            <ul class="cd-slider">
                <li class="selected"><img src="img/item-1.jpg" alt="Product 1"></li>
                <li><img src="img/item-2.jpg" alt="Product 2"></li>
                <li><img src="img/item-3.jpg" alt="Product 3"></li>
            </ul> <!-- cd-slider -->

            <ul class="cd-slider-navigation">
                <li><a class="cd-next" href="#0">Prev</a></li>
                <li><a class="cd-prev" href="#0">Next</a></li>
            </ul> <!-- cd-slider-navigation -->
        </div> <!-- cd-slider-wrapper -->

        <div class="cd-item-info">
            <h2>Fourth Item</h2>
            <p>Lorem ipsum dolor </p>

            <ul class="cd-item-action">
                <li><button class="add-to-cart">Add to cart</button></li>                   
                <li><a href="#0">Learn more</a></li>    
            </ul> <!-- cd-item-action -->
        </div> <!-- cd-item-info -->
        <a href="#0" class="cd-close">Close</a>
    </div> <!-- cd-quick-view -->
<script src="js/jquery-2.1.1.js"></script>
<script src="js/velocity.min.js"></script>
<script src="js/main.js"></script> <!-- Resource jQuery -->
</body>
</html>

javascript – ¿Como bloquear un input a solo numeros y asi como auto completar guiones en este (Aplicacion angular)?

¿podrían ayudarme?.

Varan tengo este formulario

 <form action="" method="post" enctype="multipart/form-data" class="form-horizontal" #f="ngForm"
            enctype="multipart/form-data">
            <div class="alert alert-danger mt-1 alert-dismissible" role="alert" *ngIf="ValidacionMessage">
                Por Favor verifique los campos marcados con *
                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>

            <!-- Nombre -->
            <div class="form-group row mx-1">
                <label class="col-md-3 col-form-label" for="text-input">Nombre*</label>
                <div class="col-md-9">
                    <input (disabled)="accion === 'view'" type="text" name="nombre" class="form-control"
                        placeholder="Nombre" ((ngModel))="empresa.nombre" required>
                </div>
            </div>
            <!-- Nombre -->

            <!-- Direccion -->
            <div class="form-group row mx-1">
                <label class="col-md-3 col-form-label" for="text-input">Direccion*</label>
                <div class="col-md-9">
                    <input (disabled)="accion === 'view'" type="text" name="direccion" class="form-control"
                        placeholder="Direccion" ((ngModel))="empresa.direccion" required>
                </div>
            </div>
            <!-- Direccion -->

            <!-- Registro Fiscal -->
            <div class="form-group row mx-1">
                <label class="col-md-3 col-form-label" for="text-input">Registro Fiscal*</label>
                <div class="col-md-9">

                    <input (disabled)="accion === 'view'" type="text" name="registro" class="form-control"
                        placeholder="Registro" ((ngModel))="empresa.registroFiscal" required>
                </div>
            </div>
            <!-- Registro Fiscal -->

            <!-- Telefono -->
            <div class="form-group row mx-1">
                <label class="col-md-3 col-form-label" for="text-input">Telefono*</label>
                <div class="col-md-9">
                    <input (disabled)="accion === 'view'" type="text" name="telefono" class="form-control"
                        placeholder="telefono" ((ngModel))="empresa.telefono">
                </div>
            </div>
            <!-- Telefono -->

            <!-- Tamaño -->
            <div class="form-group row mx-1">
                <label class="col-md-3 col-form-label" for="text-input">Tamaño*</label>
                <div class="col-md-9">
                    <select (disabled)="accion === 'view'" class="form-control" ((ngModel))="empresa.tamanoEmpresa_id"
                        name="tamano">
                        <option value="1">Pequeña</option>
                        <option value="2">Mediana</option>
                        <option value="3">Grande</option>
                    </select>
                </div>
            </div>
            <!-- Tamaño-->

            <!-- NIT -->
            <div class="form-group row mx-1">
                <label class="col-md-3 col-form-label" for="text-input">NIT*</label>
                <div class="col-md-9">
                    <input (disabled)="accion === 'view'" type="text" name="nit" class="form-control"
                        placeholder="Numero de NIT" ((ngModel))="empresa.nit">
                </div>
            </div>
            <!--NIT -->

            <!-- Logo -->
            <div class="form-group row mx-1" *ngIf=" accion !== 'view'">
                <label class="col-md-3 col-form-label" for="text-input">Logo*</label>
                <div class="col-md-9">
                    <div class="custom-file">
                        <input (disabled)="accion === 'view'" type="file" class="custom-file-input" name="logo"
                            ((ngModel))="empresa.logo">
                        <label class="custom-file-label" for="customFile">Elige un Logo</label>
                    </div>
                </div>
            </div>
            <!--Logo -->

            <!--Razon -->
            <div class="form-group row mx-1">
                <label class="col-md-3 col-form-label" for="text-input">Razon Social*</label>
                <div class="col-md-9">
                    <input (disabled)="accion === 'view'" type="text" name="razon" class="form-control"
                        placeholder="Razon Social" ((ngModel))="empresa.razonSocial">
                </div>
            </div>
            <!--Razon -->

            <!--Giro -->
            <div class="form-group row mx-1">
                <label class="col-md-3 col-form-label" for="text-input">Giro*</label>
                <div class="col-md-9">
                    <input (disabled)="accion === 'view'" type="text" name="giro" class="form-control"
                        placeholder="Giro" ((ngModel))="empresa.giro">
                </div>
            </div>
            <!--Giro -->


            <!--Email -->
            <div class="form-group row mx-1">
                <label class="col-md-3 col-form-label" for="text-input">Email*</label>
                <div class="col-md-9">
                    <input (disabled)="accion === 'view'" type="text" name="Email" class="form-control"
                        placeholder="Email" ((ngModel))="empresa.email" email>
                </div>
            </div>


            <div class="modal-footer">
                <button *ngIf="accion === 'create'" type="button" class="btn btn-secondary" data-dismiss="modal"
                    (click)="limpiar()">Limpiar</button>
                <button *ngIf="accion === 'create'" type="button" (click)="agregarEmpresa(f)" class="btn btn-primary"
                    name="guardar">Guardar</button>
                <button *ngIf="accion === 'editar'" type="button" (click)="editarEmpresa(f)" class="btn btn-primary"
                    name="Editar">Guardar Cambios</button>
                <button *ngIf="accion === 'view'" type="button" (click)="bsModalRef.hide()" class="btn btn-secondary"
                    name="Editar">Cerrar</button>
            </div>
        </form>

Y quisiera poder bloquear los campos registro fiscal, teléfono y nit a solamente números, me refiero a que no sea posible introducir letras ni otros caracteres, así mismo también quisiera poder auto completar un – en estos campos para ayudar al usuario, pero no realmente como hacerlo, he tratado poner type=”number” pero me aparece al costado unos controles para subir y bajar números que tampoco se como quitarlos, ¿Me pueden brindar ayudar por favor?, no he encontrado como hacer esto utilizando Angular.

heroku – JavaScript – Uncaught (in promise) DOMException: Unable to decode audio data

I am trying to deploy a game built with phaser 3, webpack and javascript with Heroku. I finally could deploy it but I got the message Uncaught (in promise) DOMException: Unable to decode audio data and Error decoding audio: bgMusic - Unable to decode audio data when I try to load the game in Chrome or Mozilla. The game is working perfectly locally but when I deploy it I do not why I got these two errors for each audio file. Any solution?

Javascript – Como adicionar coisas no html e salvar informações do html

Se o título do tópico ficou confuso peço desculpas, porque não sei como eu faria a minha pergunta de forma resumida e correta, mas é o seguinte…

Estou na reta final de um curso de informatica (acaba dia 13 desse mês) e a última tarefa do curso é criar um app para celular usando html, css e javascript e por fim fazer o porte para celular usando o Phonegap

O problema é que o curso não ensina JS (ensina apenas html e css) e eu estou com muita dificuldade em aprender JS, além da data de entrega estar muito próxima, a ideia do meu app é criar listas

inserir a descrição da imagem aqui

Conforme esta na imagem, preciso fazer uma função para que quando eu clique no botão “Adicionar Item” na página seja adicionado outra caixa (um retangulo com input e textarea dentro dele) igual as duas que estão abaixo do input para adicionar titulo a lista

Sou muito leigo com JS, assisti várias vídeo aulas para tentar aprender, mas ainda não consegui entender nem a sintaxe básica direito

O que eu gostaria de saber é: o que eu deveria focar em aprender especificamente de JS, para fazer o botão “Adicionar Item” funcionar da forma que eu descrevi, e como eu faria para que as caixas criadas e as informações digitadas pelo cliente nos inputs e textarea salvem

Desde já peço desculpas pela minha leguisse no assunto

Meu HTML (somente o da pagina da imagem)

body {}

div {
  text-align: center;
  align-items: center;
}

.botao {
  background: #00FFFF;
  cursor: pointer;
  color: black;
  border: 0;
  text-decoration: none;
  text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.5);
  border-radius: 0.5em;
  width: 300;
  font-size: 50;
  box-shadow: 2px 2px 0 1px #131;
  transition: box-shadow 0.3s ease, transform 0.3s ease;
  outline: 0;
  padding: 50px 0px 0px 0px;
}

.botao:active {
  box-shadow: 0 0 0 0 #131, inset 3px 3px 3px #131;
  transform: translate (3px, 3px);
}

.botaor {
  background: #836FFF;
  cursor: pointer;
  color: white;
  border: 0;
  text-decoration: none;
  text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.5);
  border-radius: 0.5em;
  width: 300;
  font-size: 50;
  box-shadow: 2px 2px 0 1px #131;
  transition: box-shadow 0.3s ease, transform 0.3s ease;
  outline: 0;
}

.botaor:active {
  box-shadow: 0 0 0 0 #131, inset 3px 3px 3px #131;
  transform: translate (3px, 3px);
}

.listas {
  font-size: 50;
  text-align: center
}

.loading {
  font-size: 50;
  text-align: center
}

.logo {
  width: 856;
  height: 502;
  display: block;
  margin-left: auto;
  margin-right: auto;
}

.titulo {
  width: 300;
  height: 45;
  display: block;
  margin-left: auto;
  margin-right: auto;
  font-size: 28;
}

#retangulo {
  width: 300;
  height: 200;
  border: 3px solid;
  border-color: black;
  background: white;
  margin-left: auto;
  margin-right: auto;
}

.item {
  width: 280;
  height: 45;
  margin-top: 5;
  font-size: 25;
}

.descricao {
  width: 290;
  height: 140;
  margin-top: 9;
  font-size: 20;
}

.adicionaritem {
  margin-left: 400;
  background: #00BFFF;
  cursor: pointer;
  color: white;
  border: 0;
  text-decoration: none;
  text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.5);
  border-radius: 0.5em;
  box-shadow: 2px 2px 0 1px #131;
  transition: box-shadow 0.3s ease, transform 0.3s ease;
  outline: 0;
  padding: 10px 0px 0px 0px;
  font-size: 15;
  width: 100;
}

.adicionaritem:active {
  box-shadow: 0 0 0 0 #131, inset 3px 3px 3px #131;
  transform: translate (3px, 3px);
}

.voltar {
  margin-left: 400;
  background: #00BFFF;
  cursor: pointer;
  color: black;
  border: 0;
  text-decoration: none;
  text-shadow: 2px 2px 2px rgba(0, 0, 0, 0.5);
  border-radius: 0.5em;
  box-shadow: 2px 2px 0 1px #131;
  transition: box-shadow 0.3s ease, transform 0.3s ease;
  outline: 0;
  padding: 0px 0px 0px 0px;
  font-size: 15;
  width: 100;
}

.voltar:active {
  box-shadow: 0 0 0 0 #131, inset 3px 3px 3px #131;
  transform: translate (3px, 3px);
}
<html>

<head>
  <title> Criar Lista </title>
  <link rel="stylesheet" type="text/css" href="personalizacao.css" />
  <script type="text/javascript" src="https://pt.stackoverflow.com/javascript.js">
  </script>
</head>

<body>
  <a href="2-Tela Inicial.html"> <button class="voltar"> ⬅ Voltar para o início  </button></p>
  </a>

  <input type="text" class="titulo" placeholder="Digite o Título da lista" maxlength=18>


  <button class="adicionaritem"> Adicionar item <p/>    </button> </a>


  <p> </p>




  <dl>

    <dt>
                        
                        <div id="retangulo"> 
                        
                        
                        
                        <input type="text" class="item" placeholder="Novo item" maxlength=19> 
                        
                        <textarea class="descricao"  cols="5"  rows="5" maxlength=130  >
                        
                        </textarea>
                        
                        
                        
                        
                        </dt>

    <p> </p>

    <dt>
                        
                        <div id="retangulo"> 
                        
                        
                        
                        <input type="text" class="item" placeholder="Novo item" maxlength=19> 
                        
                        <textarea class="descricao"  cols="5"  rows="5" maxlength=130  >
                        
                        </textarea>
                        
                        
                        
                        
                        </dt>

  </dl>


  </div>





</body>


</html>

css – Quiero hacer una animacion en javascript, pero todo se ejecuta al mismo tiempo

he estado intentando animar unos elementos con javascript y quiero que las animaciones pasen una por una, pero todo se ejecuta al mismo tiempo.

cards.forEach(function(item, index){ //Mover las cartas
    item.classList.add("loaded");
    item.style.transitionDuration = "1300ms"; 
    item.style.transform = "translate("+move+", 50%)";
});

el cambio de clases css es este:

.fade-in{
   opacity:0;
   -webkit-transition: opacity 2s ease-in;
   -moz-transition: opacity 2s ease-in;
   -o-transition: opacity 2s ease-in;
   -ms-transition: opacity 2s ease-in;
   transition: opacity 2s ease-in;
}

.loaded{
    opacity:1;
}

Pero como se ejecuta todo al mismo tiempo, cuando hace el fade in ya hizo la transicion de item.style.transform = "translate("+move+", 50%)"; y entonces no se ve como se mueve.

How to prevent XSS attack on selected window.location in javascript

This is my code where i have a userId in a method SwitchUser_Click. I need to prevent or somehow encode the return value from the switchUser_Click as it includes the UserId of a user vulnerable to XSS attack or redirects.

function SwitchUser_Click(containerElement, OnSuccess) {
            var selecteduserId = $("select", containerElement).val();
            var makeDefault = $(":checkbox", containerElement).is(":checked");
            window.location = "Default.aspx?uId=" + selecteduserId + "&userActive=" + (makeDefault ? "1" : "0");
            OnSuccess();
        }

The belows code is called from aspx page by using Client.RegisterScript and passing the parameters. This is the only place SwitchUser_Click method is used.

function OpenSwitchUser(UserId,modCode,defUrl) {
            defaultUrl = defUrl;
            var options =
            {
                controlUrl: "~/Controls/SwitchUserDialog.ascx",
                params: { uid:UserId, mod: modCode},
                top: 70,
                width: 600,
                height: 2500,
                OKCallback: SwitchUser_Click,
                InitCallback: SwitchUserDialog_Init,
                cancelCallback: SwitchUser_Close
            };
            $.showControlDialog(options);
        }

I want to know how to encode my userId in the SwitchUser_Click method and decode it when its called. Or maybe there is some other way to do this . Thank you

javascript – Control zoom level when using geolocate.trigger() in mapbox gl js

I am using mapbox-gl in a react app to render an interactive map. On map load, I want to center the map on the user’s location while keeping the current level of zoom. Centering on the user’s location works fine with geolocate.trigger(); but the map automatically zooms way out to the continent level. Here is a simplified version of the map component of the app. I start by setting a hard-coded center point in New York which works fine, and then when trigger() runs, it gets zoomed way out. I’ve tried fiddling with all the properties of the geolocate object, but none of them has any effect on the zoom that trigger() goes to, and trigger doesn’t seem to take any arguments. Note that I’ve had to remove my mapboxgl.accessToken for security reasons.
As a side note, I’m also trying to get rid of the larger blue location confidence circle but I also can’t seem to do that despite setting showAccuracyCircle: false. Any mapbox tips?

React component:

import React from 'react';
import mapboxgl from 'mapbox-gl';
import './map.css';

mapboxgl.accessToken = 'ACCESS_TOKEN_STRING_GOES_HERE';

export class Map extends React.Component {
  constructor(props) {
  super(props);
    this.state = {
      lng: -73.9392,
      lat: 40.8053,
      zoom: 17.5
    };
  }

  componentDidMount() {
    const map = new mapboxgl.Map({
      container: this.mapContainer,
      style: 'mapbox://styles/mapbox/streets-v11',
      center: (this.state.lng, this.state.lat),
      zoom: this.state.zoom
    });

    const geolocate = new mapboxgl.GeolocateControl({
      container: this.geolocateContainer,
      positionOptions: {enableHighAccuracy: true},
      fitBoundsOptions: {linear: true, maxZoom: 10},
      trackUserLocation: true,
      mapboxgl: mapboxgl,
      showAccuracyCircle: false
      })

    map.on('load', () => {
      geolocate.trigger();
    });

    map.addControl(geolocate);

  }

  render() {
    return (
      <div>
        <div ref={element => this.geolocateContainer = element} className='mapButtons' />
        <div ref={el => this.mapContainer = el} className='mapContainer' />
      </div>
    )
  }
}

javascript – Como agregar un enlace a otra pagina en las filas de una tabla en Angular

import {Component} from '@angular/core';

export interface PeriodicElement {
  name: string;
  position: number;
  weight: number;
  symbol: string;
}

const ELEMENT_DATA: PeriodicElement() = (
  {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},
  {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},
  {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},
  {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},
  {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'},
  {position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},
  {position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'},
  {position: 8, name: 'Oxygen', weight: 15.9994, symbol: 'O'},
  {position: 9, name: 'Fluorine', weight: 18.9984, symbol: 'F'},
  {position: 10, name: 'Neon', weight: 20.1797, symbol: 'Ne'},
);

/**
 * @title Basic use of `<mat-table>` (uses display flex)
 */
@Component({
  selector: 'table-basic-flex-example',
  styleUrls: ('table-basic-flex-example.css'),
  templateUrl: 'table-basic-flex-example.html',
})
export class TableBasicFlexExample {
  displayedColumns: string() = ('position', 'name', 'weight', 'symbol');
  dataSource = ELEMENT_DATA;
}