css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="container">
        <img id="logo"
             src="https://logorealm.com/wp-content/uploads/2016/07/Marvel-Logo.png"
             width="200"
             height="76"
             alt="Marvel">

        <div id="searchbox">
            <form id="mrvl-form" method="#">
                <label class="sr-only" for="input-name">Name</label>
                <div class="input-group mb-2 mb-sm-0">
                    <input type="text"
                           class="form-control"
                           id="input-name"
                           value="Spider-Man"
													 required>
										<input type="input-number"
                           id="results-number"
                           placeholder="number of results"
													 required>
									<button type="submit"
													class="btn btn-primary mr-3">
													Search</button>
                  <!--  <div id="input-name-addon"
                         class="input-group-addon">search</div>
                </div>-->
            </form>
        </div>

        <div id="results" class="text-center">  <!-- have to delete its content -->
					
            <ul class="character-list switch"> 
							
                <li class="list-item" data-id="1009610"> 
                    <div class="name">Spider-Man</div>  <!-- reuslt name -->
                    <div class="thumbnail">  <!-- reuslt img -->
                        <img src="http://i.annihil.us/u/prod/marvel/i/mg/3/50/526548a343e4b.jpg"
                             width="250"
                             height="250">
                    </div>
                    <div class="description" id="description"> <!-- reuslt description -->
                        Bitten by a radioactive spider, high school student Peter Parker gained the speed, strength and powers of a spider. Adopting the name Spider-Man, Peter hoped to start a career using his new abilities. Taught that with great power comes great responsibility, Spidey has vowed to use his powers to help people.
                    </div>
                </li>
                <li class="list-item" data-id="1011054">
                    <div class="name">Spider-Man (1602)</div>
                    <div class="thumbnail">
                        <img src="http://i.annihil.us/u/prod/marvel/i/mg/e/03/5317713c9e746.jpg"
                             width="250"
                             height="250">
                    </div>
                    <div class="description text-center text-muted">
                        - no description -
                    </div>
                </li>
                <li class="list-item" data-id="1014873">
                    <div class="name">Spider-Man (2099)</div>
                    <div class="thumbnail">
                        <img src="http://i.annihil.us/u/prod/marvel/i/mg/8/c0/520d1ad3e543f.jpg"
                             width="250"
                             height="250">
                    </div>
                    <div class="description text-center text-muted">
                        - no description -
                    </div>
                </li>
            </ul>
        </div><!-- /result -->

        <div id="attribution" class="text-center">
            <a href="http://marvel.com">Data provided by Marvel. © 2017 MARVEL</a>
        </div>
    </div><!-- /container -->
            
          
!
            
              body {
    background:
            radial-gradient(black 15%, transparent 16%) 0 0,
            radial-gradient(black 15%, transparent 16%) 8px 8px,
            radial-gradient(rgba(255,255,255,.1) 15%, transparent 20%) 0 1px,
            radial-gradient(rgba(255,255,255,.1) 15%, transparent 20%) 8px 9px;
    background-color:#282828;
    background-size:16px 16px;
}

.red {
    color: #DC1405;
}

.large {
    font-size: 1.5rem;
}

.text-shadow {
    text-shadow: 1px 1px 1px rgba(0,0,0,0.5);
}

h2.name {
    font-size: 1.5rem;
    font-weight: 400;
    line-height: 1.5;
    color: rgba(255,255,255,0.6);
    margin: 0 0 1rem 0;
}

#logo {
    display: block;
    margin: 3.5rem auto;
    -webkit-box-shadow: 0 0 5px 0 rgba(0,0,0,0.75);
    -moz-box-shadow: 0 0 5px 0 rgba(0,0,0,0.75);
    box-shadow: 0 0 5px 0 rgba(0,0,0,0.75);
}

#searchbox {
    text-align: center;
    max-width: 600px;
    margin: 0 auto 1rem auto;
}

#input-name , #results-number {
    background-color: rgba(255, 255, 255, 0.6);
    border-color: rgba(255,255,255,.5);
    color: #000;
    -webkit-box-shadow: 0 0 5px 0 rgba(255,255,255,0.75);
    -moz-box-shadow: 0 0 5px 0 rgba(255,255,255,0.75);
    box-shadow: 0 0 3px 0 rgba(255,255,255,0.75);
}

.btn {
    background-color: red;
    margin-left: 1rem;
    font-size: 1rem;
    color: white;
    font-weight: bold;
}



.character-list {
    padding: 0;
    margin: 0 auto;
    max-width: 640px;
    list-style: none;
}
    .character-list .list-item {
        margin: 0 0 1.5rem 0;
        padding: 1rem;
        list-style-type: none;
        border-radius: 6px;
    }

    .character-list.switch .list-item:hover {
        background: rgba(0,0,0,0.3);
        cursor: pointer;
    }

    .character-list .name {
        font-size: 1.5rem;
        color: rgba(255,255,255,0.8);
        display: inline-block;
    }

    .character-list .thumbnail {
        padding: 1rem 0;
    }
        .character-list .thumbnail img {
            max-width: 250px;
            border-radius: 6px;
        }

    .character-list .description {
        font-size: 1.25rem;
        color: #c0c0c0;
        max-width: 600px;
        margin: 0 auto;
        padding: 1rem 0;
        text-align :justify;
    }

.flat-list {
    margin: 0;
    padding: 0;
    list-style-type: none;
}
    .flat-list .list-item {
        color: rgba(255,255,255,0.8);
        font-size: 1.25rem;
        text-align: left;
        margin: 0;
        padding: 0;
    }

#attribution {
    margin: 1.5rem 0;
}
    #attribution a {
        color: rgba(255, 255, 255, 0.6);
    }

.input-group ::placeholder {
  color: black;
  opacity: 0.5;
}

.not-found {
  color: red;
  font-size: 2rem;
}

.hidden {
  display: none;
}

            
          
!
            
              $('#input-name').focus()

$('#mrvl-form').submit((e) => {
  e.preventDefault()
})

class MarvelAPI {
  constructor () {
    this.baseURL = 'https://gateway.marvel.com:443/v1/public/characters?'
    this.key = '0c9de53047baf1a98184cc4c67e032de'
    this.elements = {
      'form': $('#mrvl-form'),
      'input': $('#input-name'),
      'resultsNumber': $('#results-number'),
      'results': $('#results'),
      'img': $('#result-image'),
      'description': $('#description'),
      'comics': $('#comics-list'),
      'series': $('#series-list')
    }

    this.params = {
      'apikey': '0c9de53047baf1a98184cc4c67e032de',
      'orderBy': 'name',
      'limit': 30,
      'offset': 0
    }

    this.registerEvents()
  } // constructor

  callApi (options, callback) {
    //  let resultNumber = this.elements.resultsNumber.val()
    const fullURL = `${this.baseURL}`

    this.params = $.extend(this.params, options)

    $.getJSON(fullURL, this.params)
      .done((data) => {
        callback(data)
      })
      .fail((response) => {
        callback(null)
      })
  }

  getCharacterByName (name, callback) {
    delete this.params.nameStartsWith

    this.callApi(
      {
        'name': name,
        'limit': this.elements.resultsNumber.val()
      },
      (data) => {
        this.showData(data.data)
      }
    )
  }

  getCharacterByNameStartsWith (name, callback) {
    delete this.params.name

    this.callApi(
      {
        'nameStartsWith': name,
        'limit': this.elements.resultsNumber.val()
      },
      (data) => {
        this.showData(data.data)
      }
    )
  }

  registerEvents () {
    this.elements.form.on('submit', (e) => {
      e.preventDefault()

      this.getCharacterByName(
        this.elements.input.val().trim(),
        (data) => {
        }
      )

      this.getCharacterByNameStartsWith(
        this.elements.input.val().trim(),
        (data) => {
        }
      )
    })
  }

  showData (data) {
    this.elements.results.html('')

    if (data.results.length === 0) {
      this.elements.results.append(`<p class="not-found"> - Sorry no results found - </p> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEgAAABICAMAAABiM0N1AAAAz1BMVEVHcEz/xkD+y0b6vhn7vA/9ykb9xzr6uQj8xTX/xjT7vRRk0fj8xzz/wi7+xzn7vxtdzvb9ykdczvZZzvR50uxt1f39ykb9ykf0tSL9ykf5twAwLDt11v+RdST/6LtXzPP7vhb5yEfxwEX8xzrDnThXSj3jtkG66v/+1W8/Nzywji7RqUX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F5La7QBB7HV2ZEelgKubW4zO7jUBBfCgLYq/sawG0UxbEDhHXXR70pnQ4IoLYseYuA4RWK5SeGHequetepYEsextUS1wVt/LhAZ+xBIdIajyJA1lCbcI1yIobxB9Gb7s4QsxV94e9I/ejlhSjfYwjHI/vCOmKBP5l54x1KyHWEkc8sN93j/GxCRWRCj2ar/cT10LIWk3s9XzEVXHKAdKn1i3H2UQGOdtokMdeMNuwoHmUA2MfNQ/XAeZnstlY5yxoAGWjOdb9Q+7PZrM6dx2mccLKBKbZnx9hWqB28qO21OufzirEwFLGF3tFg72pl4mBWvYdgo7PhImy+lMQYYB+1pVGEQ8AvWnf44yZ9hgFguK5tyP5Ih0FejQgH6CocvdTaZZgYpSaFdUrpHqzCkQIqDbrF95q1fVitVrCUa0W9Ubud8Vf98mGAUzPxdkAAAAASUVORK5CYII=">`)
      return
    }

    
    data.results.forEach((item) => {
      let description = '- no description -'
      // comics list
      let comics = `<ul class="flat-list" id="comics-list"> <h2 style="color:white"> Comics</h2>`

      item.comics.items.forEach((comic) => {
        comics += `<li class="list-item"><p>${comic.name}</p></li>`
      })

      comics += `</ul>`

      // series list
      let series = `<ul class="flat-list" id="series-list"> <h2 style="color:white"> Series</h2>`

      item.series.items.forEach((serie) => {
        series += `<li class="list-item"><p>${serie.name}</p></li>`
      })

      series += `</ul>`

      if (item.description.length > 0) {
        description = item.description
      }

      this.elements.results.append(`
            <ul class="character-list switch">
                <li class="list-item" data-id="1009610">
                    <div class="name">${item.name}</div>
                    <div class="thumbnail">
                        <img src="${item.thumbnail.path}.${item.thumbnail.extension}"
                             width="250"
                             height="250">
                    </div>

                    <div class="description text-center" id="description">
                        <p> ${description} </p>
                    </div>

                    <div class="hidden comics text-center">
                           ${comics}
                    </div>

                    <div class="hidden series text-center">
                           ${series}
                    </div>


                    </div>
                </li>
            </ul>
      `)
    })

    $('#results .list-item').click((event) => {
      $(event.currentTarget).find('.comics').toggleClass('hidden')
      $(event.currentTarget).find('.series').toggleClass('hidden')
    })
  }
} // class

const mrvl = new MarvelAPI();

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console