Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // rsGalleries.js by Dennis Amrouche | www.screenlabor.de | freie media hamburg
- // this script was written with friendly support of ...
- // - atula from NYC/USA @ #jquery irc-channel/freenode/europe
- // - sven lauritzen @ www.sven-lauritzen.de, freelance coder located in hamburg
- // - some beer in café miller / st. pauli hamburg
- $(function() {
- rsGalleries.init();
- });
- if (typeof console == "undefined") {
- console = {
- log:function() {
- }
- }
- }
- rsGalleries = {
- scrollerHeight: 330,
- init:function() {
- this.initStart();
- this.initTabs();
- this.initScrollers();
- this.initSwap();
- },
- initStart:function() {
- //enable all starting categories
- $(".tabs").addClass("hide");
- $("#start").addClass("show");
- $("#food").addClass("show");
- },
- initTabs:function() {
- // change categories
- $("a.switch").click(function() {
- var cat = $(this).attr("href").substr(1);
- $(this).parents(".tabholder").find(".tab").addClass("hide");
- $(this).parents(".tabholder").find("#"+cat).addClass("show");
- // $(this).parents(".tabholder").find("a.switch").removeClass("selected");
- // $(this).parents(".tabholder").find("a.switch").addClass("selected");
- return false;
- });
- },
- initSwap:function() {
- // find all images with the class thumb and bind a click event to it
- $("a.thumb").click(function() {
- $(this).parents(".thumbrow").find("a.thumb").removeClass("selected");
- $(this).addClass("selected");
- // getting the src text and getting the number out..
- var path = $(this).find("img").attr("src").replace("-thmb-","-photo-");
- // grabbing the photo that's being displayed
- var photo = $(this).parents(".gallery").find(".photo img");
- // the same procedure to get the number in the image name
- var curr = photo.attr("src");
- // here I'm comparing, if the image displayed is not equal to the thumb I'm clicking (!=) do this
- if (path != curr) {
- // photo is the variable I created to reference the photo being displayed
- // fadeOut("fast") is a jquery effect
- // .attr( is changing the attribute.. src of the image... then fadeIn(
- photo.fadeOut("fast", function() {
- photo.attr("src", path).fadeIn("slow");
- });
- }
- return false;
- });
- },
- initScrollers:function(gallery) {
- // OnClick-Event auf den down-Pfeil
- if((typeof gallery)=="undefined") {
- gallery=$(".gallery")
- }
- $(gallery).each(function() {
- var position = parseInt($(this).find(".thumbrow").css("margin-top").replace("px",""));
- var up=$(this).find("li.up");
- var down=$(this).find("li.down");
- if(-position/rsGalleries.scrollerHeight < Math.ceil($(this).find("a.thumb").length/5)-1) {
- $(down).find("img").wrap('<a href="#" class="down"></a>');
- $(down).find("a").click(function() {
- // Suche und finde die thumbrow die animiert werden soll
- var currGallery=$(this).parents(".gallery");
- var thumbrow = currGallery.find(".thumbrow");
- // disable all scroll links
- $(this).parents("ul").find("li").each(function(i) {
- var anchor=$(this).find("a");
- if(anchor.length>0) {
- $(this).html($(anchor).html());
- }
- });
- // grabbing value of margin
- var position = parseInt($(thumbrow).css("margin-top").replace("px",""));
- // animate thumbrow vertically via CSS margin-top
- $(thumbrow).animate({marginTop:position-rsGalleries.scrollerHeight}, "slow", function() {
- rsGalleries.initScrollers(currGallery);
- });
- return false;
- });
- }
- if(position<0) {
- $(up).find("img").wrap('<a href="#" class="up"></a>');
- $(up).find("a").click(function() {
- var currGallery=$(this).parents(".gallery");
- var thumbrow = currGallery.find(".thumbrow");
- // disable all scroll links
- $(this).parents("ul").find("li").each(function(i) {
- var anchor=$(this).find("a");
- if(anchor.length>0) {
- $(this).html($(anchor).html());
- }
- });
- var position = parseInt($(thumbrow).css("margin-top").replace("px",""));
- $(thumbrow).animate({marginTop:position+rsGalleries.scrollerHeight}, "slow", function() {
- rsGalleries.initScrollers(currGallery);
- });
- return false;
- });
- }
- });
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement