jquery - Why is my javascript not functioning? -


i'm using layout codepen: http://codepen.io/trhino/pen/ytoqv

and have put parts of code html not functioning. can tell me why , can fix it? want codepen tutorial actual image gallery effect , 'click expand' , 'collapse' buttons.

here site looks @ minute (ignore stretched photos, correcting once have sorted javascript)

http://me14ch.leedsnewmedia.net/portfolio/photo.html

really appreciate help! code:

    <h2>(click on box expand gallery)</h2>   <div class="wrap">   <div id="picture1" class="deck">        <img src="http://www.me14ch.leedsnewmedia.net/portfolio/gallery/newyork1.jpg">       </a>     </div>   <div id="picture2" class="deck">       <img src="http://www.me14ch.leedsnewmedia.net/portfolio/gallery/newyork2.jpg">       </a></div>   <div id="picture3" class="deck">        <img src="http://www.me14ch.leedsnewmedia.net/portfolio/gallery/newyork3.jpg">       </a></div>   <div id="picture4" class="deck">       <img src="http://www.me14ch.leedsnewmedia.net/portfolio/gallery/newyork4.jpg">       </a></div>   <div id="picture5" class="deck">       <img src="http://www.me14ch.leedsnewmedia.net/portfolio/gallery/newyork5.jpg">       </a></div> </div>         <div id="close"><p>&laquo; collapse gallery</p></div>     <div id="lightbox"> <div id="lightwrap">  <div id="x"></div> </div> 

this css

    /* gallery */  *, *::before, *::after {   -moz-box-sizing: border-box;   box-sizing: border-box; }  p {   font-family: arial, helvetica, sans-serif;   font-size: 24px;   color: #6cbdeb;   text-shadow: 1px 1px 1px #000; }  .wrap {   position: relative;   width: 1125px;   height: 200px;   margin: 0 auto; }  .deck {   margin: 20px;   border: 3px solid #fadbc8;   height: 202px;   width: 202px;   position: absolute;   top: 0;   left: 0;   transition: .3s;   cursor: pointer;   font-size: 50px;   line-height:200px;   text-align: center;  }  .deck {   color: black; }  .deck img {   height: 200px;   width: 200px; }  .album {   border: 1px solid #fadbc8;   height: 200px;   width: 200px;   float: left;   transition: .3s;   position: relative; }  #close {   position: relative;   display: none;     width: 1125px;   margin: 30px auto 0; }  #close p {   cursor: pointer;   text-align: right;   margin: 0 20px 0; } #lightbox {   position: fixed;   top: 0;   left: 0;   height: 100%;   width: 100%;   background: rgba(0, 0, 0, 0.7);   display: none;   z-index: 999; }  #lightwrap {   position: relative;   margin: 0 auto;   border: 5px solid black;   top: 15%;   display: table; }  #lightwrap img {   display: table-cell;   max-width: 600px; }  #x {   position: absolute;   top: 2px;   right: 2px;   background-image: url(data:image/png;base64,ivborw0kggoaaaansuheugaaabsaaaabcamaaac6cgrnaaaapfbmvex///8aaad9/f2cgokagiaaaaaaaaaaaabls0saaaaaaacqqqqqqqq6urpkskpisegaaac7u7u5ubn////zbsmcaaaae3rstlmasv6rqwaws5ymc7/ayzwvfcrjcyakfaaaahhjrefuef590kkogcaqrfeafvgc+/53fymbz6jqbbyqmfsyuoquv+itflnsti7sslxrvmwraems84e2uvckuze6knl0hispobxhj6chzoekioliipkio4joicaiedd7qgifccjoke9hek8mnxpiaup/f31rpzp9fag3iaybsje0igaaaabjru5erkjggg==);   width: 27px;   height: 27px;   cursor: pointer; } 

and javascript:

 var i, expand = false;  function reset() {   $('.deck').css({     'transform': 'rotate(0deg)',     'top'      : '0px'   }); }  //expands , contracts deck on click $('.deck').click(function (a) {   if (expand) {     a.preventdefault();     var imgsource = $(this).children().attr('href');     $('#lightwrap').append('<img src="' + imgsource + '" id="lb-pic">');     $('#lightbox, #lightwrap').fadein('slow');   } else {     var boxwidth = $('.deck').width();     $('.deck').each(function (e) {       $(this).css({         'left': boxwidth * e * 1.1 + 'px'       });       expand = true;       $('#close').show();     });   } });  //close lightbox $('#x, #lightbox').click(function(){   $('#lightbox').fadeout('slow');   $('#lightwrap').hide();   $('#lb-pic').remove(); });  //prevent event bubbling on lightbox child $('#lightwrap').click(function(b) {   b.stoppropagation(); });  $('#close').click(function(){   $(this).hide();   $('.deck').css({'left': '0px'});   expand = false; });  $('.deck:last-child').hover(   //random image rotation    function() {     if (expand === false) {           $('.deck').each(function () {         i++;         if (i < $('.deck').length) {           var min = -30,               max = 30,               random = ~~(math.random() * (max - min + 1)) + min;           $(this).css({             'transform' : 'rotate(' + random + 'deg)',             'top'       : random + 15 + 'px'           });         }       });     }   //straightens out deck images when clicked   $('.deck').click(     function (a) {       a.preventdefault();       reset();     });    },   //undo image rotation when not hovered   function () {     = 0;     reset();   } ); 

just enclose javascript in $( document ).ready() function in order execute on load of page:

$( document ).ready(function() {   //paste javascript code here }); 

the result this:

enter image description here

here jsbin it


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -