Solved

Jquery Colorbox

Posted on 2010-11-24
6
547 Views
Last Modified: 2012-05-10
I'm developing a site that uses a colorbox to view a larger version of the product.

http://www.bohemia.arrivaldesign.co.uk/boutique/dresses/dilema_dress

My dilemma is that I need the images to scroll through when you're in the colorbox using the next/previous arrows, this is working fine for the initial load of the page, if you click the magnifying glass, but once you click on the numbered boxes, I can get the colorbox to load at the correct point, with the same image and in the correct order, but I can't seem to get the next/previous arrows to work?

Any ideas?

Thanks,

Chris
<script type="text/javascript"> 
	$(document).ready(function(){ 
			$('a[rel=zoomer]').colorbox(); 
			$('.display_slides').click(function(){ 
				if ($(this).attr("id") == "no1") {
					$("a[rel='zoomer']:eq(0)").click(); 
				}
				else if ($(this).attr("id") == "no2") {
					$("a[rel='zoomer']:eq(1)").click(); 
				}
				else if ($(this).attr("id") == "no3") {
					$("a[rel='zoomer']:eq(2)").click(); 
				}
				else if ($(this).attr("id") == "no4") {
					$("a[rel='zoomer']:eq(3)").click(); 
				}
				return false; 
			}) 
			$("#prod_img li a").click(function(event){
				$("#prod_img li a").removeClass("onstate");
				var newNo = $(this).attr("rel");
				$(".display_slides").attr("id", newNo);
				$(this).addClass("onstate");
				$("img#mainpic").hide();
				var newSRC = $(this).attr("href");
				$("img#mainpic").attr("src", "/garments/page_" + newSRC).fadeIn();
				var newZoom = $(this).attr("href");
				$("a[rel='zoomer']").attr("href", "/garments/" + newZoom);
				event.preventDefault();
			});
	}); 
</script> 
 
<div class="hide"> 
                <a href="/garments/b4864.jpg" rel="zoomer" id="zoom1" title="Dilema Dress">1</a>
                                <a href="/garments/asd63.jpg" rel="zoomer" id="zoom2" title="Dilema Dress">2</a>
                                <a href="/garments/6pu65.jpg" rel="zoomer" id="zoom3" title="Dilema Dress">3</a>
                                <a href="/garments/ftbclose up.jpg" rel="zoomer" id="zoom4" title="Dilema Dress">4</a>
                                </div> 
 
    <div id="prod_img">
      <div class="pg_image"><img src="/garments/page_b4864.jpg" name="mainpic" width="238" height="306" id="mainpic" /><a href="/garments/b4864.jpg" title="Dilema Dress" class="display_slides" id="no1"><img src="/images/zoom.gif" alt="Enlarge" width="21" height="21" class="zoom" /></a></div>
      <ul>
        <li><a href="b4864.jpg" class="onstate" rel="no1">1</a></li>
                <li><a href="asd63.jpg" rel="no2">2</a></li>
                <li><a href="6pu65.jpg" rel="no3">3</a></li>
                <li><a href="ftbclose up.jpg" rel="no4">4</a></li>
              </ul>
    </div>

Open in new window

0
Comment
Question by:djfenom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
Sudaraka Wijesinghe earned 250 total points
ID: 34204265
The left right navigation is working fine even after you click the numbers.
The problem is when the number is clicked, you are resetting the href of all your rel=zoomer to the same image.
<script type="text/javascript"> 
        $(document).ready(function(){ 
                        $('a[rel=zoomer]').colorbox(); 
                        $('.display_slides').click(function(){ 
                                if ($(this).attr("id") == "no1") {
                                        $("a[rel='zoomer']:eq(0)").click(); 
                                }
                                else if ($(this).attr("id") == "no2") {
                                        $("a[rel='zoomer']:eq(1)").click(); 
                                }
                                else if ($(this).attr("id") == "no3") {
                                        $("a[rel='zoomer']:eq(2)").click(); 
                                }
                                else if ($(this).attr("id") == "no4") {
                                        $("a[rel='zoomer']:eq(3)").click(); 
                                }
                                return false; 
                        }) 
                        $("#prod_img li a").click(function(event){
                                $("#prod_img li a").removeClass("onstate");
                                var newNo = $(this).attr("rel");
                                $(".display_slides").attr("id", newNo);
                                $(this).addClass("onstate");
                                $("img#mainpic").hide();
                                var newSRC = $(this).attr("href");
                                $("img#mainpic").attr("src", "/garments/page_" + newSRC).fadeIn();
                                var newZoom = $(this).attr("href");
                                $("a[rel='zoomer']").attr("href", "/garments/" + newZoom); // <-- PROBLEM IS HERE
                                event.preventDefault();
                        });
        }); 
</script> 
 
<div class="hide"> 
                <a href="/garments/b4864.jpg" rel="zoomer" id="zoom1" title="Dilema Dress">1</a>
                                <a href="/garments/asd63.jpg" rel="zoomer" id="zoom2" title="Dilema Dress">2</a>
                                <a href="/garments/6pu65.jpg" rel="zoomer" id="zoom3" title="Dilema Dress">3</a>
                                <a href="/garments/ftbclose up.jpg" rel="zoomer" id="zoom4" title="Dilema Dress">4</a>
                                </div> 
 
    <div id="prod_img">
      <div class="pg_image"><img src="/garments/page_b4864.jpg" name="mainpic" width="238" height="306" id="mainpic" /><a href="/garments/b4864.jpg" title="Dilema Dress" class="display_slides" id="no1"><img src="/images/zoom.gif" alt="Enlarge" width="21" height="21" class="zoom" /></a></div>
      <ul>
        <li><a href="b4864.jpg" class="onstate" rel="no1">1</a></li>
                <li><a href="asd63.jpg" rel="no2">2</a></li>
                <li><a href="6pu65.jpg" rel="no3">3</a></li>
                <li><a href="ftbclose up.jpg" rel="no4">4</a></li>
              </ul>
    </div>

Open in new window

0
 

Author Comment

by:djfenom
ID: 34204309
Thanks sudaraka, how would I go about fixing this?

Chris
0
 
LVL 8

Assisted Solution

by:kivan24
kivan24 earned 250 total points
ID: 34204316
Let's look page source

When you load page first time:
<div class="hide"> 
    <a href="/garments/b4864.jpg" rel="zoomer" id="zoom1" title="Dilema Dress">1</a>
    <a href="/garments/asd63.jpg" rel="zoomer" id="zoom2" title="Dilema Dress">2</a>
    <a href="/garments/6pu65.jpg" rel="zoomer" id="zoom3" title="Dilema Dress">3</a>
    <a href="/garments/ftbclose up.jpg" rel="zoomer" id="zoom4" title="Dilema Dress">4</a>
</div>

Open in new window

everything ok

When you click on the numbered boxe 2:
<div class="hide"> 
    <a class="cboxelement" href="/garments/asd63.jpg" rel="zoomer" id="zoom1" title="Dilema Dress">1</a>
    <a class="cboxelement" href="/garments/asd63.jpg" rel="zoomer" id="zoom2" title="Dilema Dress">2</a>
    <a class="cboxelement" href="/garments/asd63.jpg" rel="zoomer" id="zoom3" title="Dilema Dress">3</a>
    <a class="cboxelement" href="/garments/asd63.jpg" rel="zoomer" id="zoom4" title="Dilema Dress">4</a>
</div>

Open in new window


When you click on the numbered boxe 3:
<div class="hide"> 
   <a class="cboxelement" href="/garments/6pu65.jpg" rel="zoomer" id="zoom1" title="Dilema Dress">1</a>
   <a class="cboxelement" href="/garments/6pu65.jpg" rel="zoomer" id="zoom2" title="Dilema Dress">2</a>
   <a class="cboxelement" href="/garments/6pu65.jpg" rel="zoomer" id="zoom3" title="Dilema Dress">3</a>
   <a class="cboxelement" href="/garments/6pu65.jpg" rel="zoomer" id="zoom4" title="Dilema Dress">4</a>
</div>

Open in new window

When you click on numbered boxes all A tag link to the same file.
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34204423
Is it necessary to change the href on click? I think you already have all the correct images set on page load right?
0
 

Author Comment

by:djfenom
ID: 34204478
Ahhh, fixed it, just took out this line:

$("a[rel='zoomer']").attr("href", "/garments/" + newZoom);

Thanks guys.

Chris
0
 
LVL 18

Expert Comment

by:Sudaraka Wijesinghe
ID: 34204499
Yup, that's it :)
Glad to help, Thanks for the points.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jQuery element reference issue 2 40
Add Rows on a Table 8 55
why is my slideshow so small on this wordpress site? 7 41
type of website 13 54
Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question