Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Here is what I am working with:

  <script>

  $(document).ready(function() {

  $("#cf7_controls").on('click', 'span', function() {

  $("#cf7 img").removeClass("opaque");

  var newImage = $(this).index();

  $("#cf7 img").eq(newImage).addClass("opaque");

  $("#cf7_controls span").removeClass("selected");

  $(this).addClass("selected");

  });

  });

  </script>   <div class="row">
    <div class="span 6">
        <div id="cf7" class="shadow">
            <img class='opaque' src="/img/Cirques.jpg" />
            <img src="/img/ClownFish.jpg" />
            <img src="/img/Stones.jpg" />
            <img src="/img/Summit.jpg" />
        </div>
        <p id="cf7_controls">
            <span class="selected">Image 1</span>
            <span>Image 2</span>
            <span>Image 3</span>
            <span>Image 4</span>
        </p>
    </div>
    <div class="span 6">
        <div id="cf7" class="shadow">
            <img class='opaque' src="img/Cirques.jpg" />
            <img src="img/ClownFish.jpg" />
            <img src="img/Stones.jpg" />
            <img src="img/Summit.jpg" />
        </div>
        <p id="cf7_controls">
            <span class="selected">Image 1</span>
            <span>Image 2</span>
            <span>Image 3</span>
            <span>Image 4</span>
        </p>
    </div>

I pulled this code from http://css3.bradshawenterprises.com/cfimg/#cfimg7

Unfortunately, it doesn't work right. A live demo of my WIP can be viewed on http://marc-with-a-c.com

The error in google chrome is: Uncaught ReferenceError: $ is not defined marc-with-a-c.com/:97

Thanks for helping!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
136 views
Welcome To Ask or Share your Answers For Others

1 Answer

You does not have jQuery library included in the page

Add the line to include jQuery before the script element:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
    $(document).ready(function() {

        $("#cf7_controls").on('click', 'span', function() {
            $("#cf7 img").removeClass("opaque");

            var newImage = $(this).index();

            $("#cf7 img").eq(newImage).addClass("opaque");
            $("#cf7_controls span").removeClass("selected");
            $(this).addClass("selected");
        });
    });
</script>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...