javascript - How do I make my thumbnail as a link and the title append to the right? -
want create thumbnail link, as, putting title right of thumbnail.
i tried using after , messed html see if can span them next each other.
how go doing so?
here js:
$(function(){ var search = function(term, el){ $.get('https://www.googleapis.com/youtube/v3/search', { part: 'snippet', key: 'aizasya8dm-n-qcxpgkvkwii0lky0ak4zpgfp3c', q: term, maxresults: 25 }, function(data){ display(data.items, el); }); }; var display = function(videos, el){ el.empty(); $.each(videos, function(index, video){ var thumbnail = video.snippet.thumbnails.default.url; var vidtitle = video.snippet.title; var vidid = video.id.videoid; var container = $('<span/>', { 'class': 'video-container' }); var thumbcontainer = $('<div/>', { 'class': 'thumbnail' }); var thumbnailelement = $('<img/>', { 'src': thumbnail }); var thumbnaillink = $('<a/>', {'src': thumbnail}); thumbcontainer.append(thumbnailelement).append(thumbnaillink); var titlecontainer = $('<span/>', { 'class': 'title' }); var titleelement = $('<a/>', { 'href': 'https://www.youtube.com/watch?v='+vidid, 'target': '_blank', 'html': vidtitle, }); titlecontainer.append(titleelement); container.append(thumbcontainer).append(titlecontainer); el.append(container); }); }; //jquery event listeners $('.search-btn').on('click', function(event){ event.preventdefault(); var searchinput = $('.search-field').val(); search(searchinput, $('#search-results')); }); });
here html:
<body> <div class="container"> <div class="master-nav"> <form class="search-nav"> <span> <img src="https://www.thinkful.com/learn/static/shared/images/tf-logo-blue-t-1200x1200.png"> </span> <span class="brand"> <h1>hinkful tube</h1> </span> <span class="search-query"><input class="search-field"> <button class="search-btn">submit</button> </span> </form> </div> <div id="search-container"> <div id="search-results"> <span class="video-container"></span> <span class="title"></span> </div> </div> </div> </body>
here css:
.container { margin: 0 auto; font-family: arial; color: #4628fb; } .master-nav { background-color: white; height: 4.375rem; width: 100%; border-bottom: 1px solid #4628fb; z-index: 9999; } .search-nav { width: 1000px; margin: 0 auto; } .search-query{ float: right; padding: 10px 10px; } .brand{ float: left; padding-left: 0px; } #search-results { } #search-container { width: 1000px; margin: 10px auto; } .search-nav img { width: 5%; float:left; padding-top: 10px }
<!doctype html> <html lang="en"> <head> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <style> .video-container{display:inline-block; width:100%} .thumbnail{float:left;} .container { margin: 0 auto; font-family: arial; color: #4628fb; } .master-nav { background-color: white; height: 4.375rem; width: 100%; border-bottom: 1px solid #4628fb; z-index: 9999; } .search-nav { width: 1000px; margin: 0 auto; } .search-query{ float: right; padding: 10px 10px; } .brand{ float: left; padding-left: 0px; } #search-results { } #search-container { width: 1000px; margin: 10px auto; } .search-nav img { width: 5%; float:left; padding-top: 10px } </style> </head> <body> <div class="container"> <div class="master-nav"> <form class="search-nav"> <span> <img src="https://www.thinkful.com/learn/static/shared/images/tf-logo-blue-t-1200x1200.png"> </span> <span class="brand"> <h1>hinkful tube</h1> </span> <span class="search-query"><input class="search-field"> <button class="search-btn">submit</button> </span> </form> </div> <div id="search-container"> <div id="search-results"> <span class="video-container"></span> <span class="title"></span> </div> </div> </div> <script type="text/javascript"> $(function(){ var search = function(term, el){ $.get('https://www.googleapis.com/youtube/v3/search', { part: 'snippet', key: 'aizasya8dm-n-qcxpgkvkwii0lky0ak4zpgfp3c', q: term, maxresults: 25 }, function(data){ display(data.items, el); }); }; var display = function(videos, el){ el.empty(); $.each(videos, function(index, video) { var thumbnail = video.snippet.thumbnails.default.url; var vidtitle = video.snippet.title; var vidid = video.id.videoid; var element = "<span class='video-container'><div class='thumbnail'><a href='https://www.youtube.com/watch?v="+vidid+"' target='_blank'><img src='"+thumbnail+"'></a></div><span class='title'>"+vidtitle+"</span></span>"; el.append(element); }); }; //jquery event listeners $('.search-btn').on('click', function(event){ event.preventdefault(); var searchinput = $('.search-field').val(); search(searchinput, $('#search-results')); }); }); </script> </body> </html>
Comments
Post a Comment