jquery - Javascript Linking issue -
i've been working on courasel think it's called or slider im trying link js file isn't functioning , can't put finger on issue. i'm trying display pictures ability move next , previous click of button; once item clicked their's pop-out window supplied "fancybox" js. have downloaded jquery library , saved "query.js"
<html> <head> <link rel="stylesheet" type="text/css" href="attempt2.css"> <script src="attempt2.js"></script> </head> <body> <div class="gallery-wrap"> <div class="gallery clearfix"> <div class="gallery__item"> <img src="images/image1.jpg" class="gallery__img" alt="" /> </div> <div class="gallery__item"> <img src="images/image2.jpg" class="gallery__img" alt="" /> </div> <div class="gallery__item"> <img src="images/image3.jpg" class="gallery__img" alt="" /> </div> <div class="gallery__item"> <img src="images/image4.jpg" class="gallery__img" alt="" /> </div> <div class="gallery__item"> <img src="images/image5.jpg" class="gallery__img" alt="" /> </div> </div> <div class="gallery__controls clearfix"> <div href="#" class="gallery__controls-prev"> <img src="images/prev.png" alt="" /> </div> <div href="#" class="gallery__controls-next"> <img src="images/next.png" alt="" /> </div> </div> </div> <script type="text/javascript" src="query.js"></script> <script type="text/javascript" src="./fancybox/jquery.fancybox-1.3.1.js"></script> <link rel="stylesheet" href="/fancybox/source/jquery.fancybox.css?v=2.1.5" type="text/css" media="screen"/> <script type="text/javascript" src="/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script> <script type="text/javascript"> // run once page has loaded $(window).load(function(){ // fancybox specific $(".gallery__link").fancybox({ 'titleshow' : false, 'transitionin' : 'elastic', 'transitionout' : 'elastic' }); // set general variables // ==================================================================== var totalwidth = 0; // total width calculated looping through each gallery item , // adding each width , storing in `totalwidth` $(".gallery__item").each(function(){ totalwidth = totalwidth + $(this).outerwidth(true); }); // maxscrollposition furthest point items should // ever scroll to. want viewport full of images. var maxscrollposition = totalwidth - $(".gallery-wrap").outerwidth(); // core function animates target item // ==================================================================== function togalleryitem($targetitem){ // make sure target item exists, otherwise nothing if($targetitem.length){ // new position left of targetitem var newposition = $targetitem.position().left; // if new position isn't greater maximum width if(newposition <= maxscrollposition){ // add active class target item $targetitem.addclass("gallery__item--active"); // remove active class other items $targetitem.siblings().removeclass("gallery__item--active"); // animate .gallery element correct left position. $(".gallery").animate({ left : - newposition }); } else { // animate .gallery element correct left position. $(".gallery").animate({ left : - maxscrollposition }); }; }; }; // basic html manipulation // ==================================================================== // set gallery width totalwidth. allows items // on 1 line. $(".gallery").width(totalwidth); // add active class first gallery item $(".gallery__item:first").addclass("gallery__item--active"); // when prev button clicked // ==================================================================== $(".gallery__controls-prev").click(function(){ // set target item item before active item var $targetitem = $(".gallery__item--active").prev(); togalleryitem($targetitem); }); // when next button clicked // ==================================================================== $(".gallery__controls-next").click(function(){ // set target item item after active item var $targetitem = $(".gallery__item--active").next(); togalleryitem($targetitem); }); }); </script> </body> </html>
in embedded script on html page, you've referred fancybox items '.gallery__link' , haven't used links fancybox use. so, you've written:
<div class="gallery__item"> <img src="images/image3.jpg" class="gallery__img" alt="" /> </div> it should be:
<a href="images/image3.jpg" class="gallery__link"> <img src="images/image3.jpg" /> </a> here's quick guide on fancybox website of how different things:
don't hesitate leave comment if need more help
here's link simple zip contains basic html page required links , javascript.
Comments
Post a Comment