summaryrefslogtreecommitdiffstats
path: root/jquery-img-rotator.xhtml
blob: cea34b80351db5392a64a36f3052aea49ec812a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Image Rotator</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">
    #imglist {
        position: relative;
        width: 630px;
        height: 420px;
    }
    <!-- div tags inside of #imglist block -->
    #imglist div {
        position: absolute;
        z-index: 0;
    }
    #imglist div.previous {
        z-index: 1;
    }
    #imglist div.current {
        z-index: 2;
    }
    #tooltip1 {
        position: absolute;
        display: none;
        opacity: 0.0;
    }
</style>
<script type="text/javascript" src="jquery-1.10.1.min.js"></script>
<script type="text/javascript">
<![CDATA[
    $(function() {
        $("#viewlarger").hover(
            function() {
                var offset = $("#viewlarger").offset();
                console.log(JSON.stringify(offset));
                $("#tooltip1").css({top: offset.top, left: offset.left}).css("display", "block").animate({opacity: 1.0}, 300);
            },
            function() {
                $("#tooltip1").animate({opacity: 0.0}, 300, function() {
                    $(this).css("display", "none");
                });
            }
        );

        setInterval(rotateImages, 4000);
    });

    function rotateImages() {
        var currImg = $('#imglist div.current');
        var nextImg = currImg.next();
        if (nextImg.length == 0)
            nextImg = $("#imglist div:first");

        <!-- current img is now 1 step underneath the next img -->
        currImg.removeClass("current").addClass("previous");
        <!-- next img is now at the top of stack, and is transparent, so previous still stays on for some interval -->
        nextImg.css({opacity: 0.0}).addClass("current").animate({opacity: 1.0}, 1000,
            function() {
                currImg.removeClass("previous"); <!-- remember that we started with only 1 div having current class --->
            });
    }
    
]]>
</script>
</head>
<body>
<h1>Image Rotator</h1>
<div id="imglist">
  <div class="current"><img class="imgslides" src="subbies/img1.jpg" alt="img1" width="630" height="420px" /></div>
  <div><img class="imgslides" src="subbies/img2.jpg" alt="img2" width="630px" height="420px" /></div>
  <div><img class="imgslides" src="subbies/img3.jpg" alt="img3" width="630px" height="420px" /></div>
  <div><img class="imgslides" src="subbies/img4.jpg" alt="img4" width="630px" height="420px" /></div>
</div>
<h1>Tooltip</h1>
<p>this is my dream ride:<br />
<a id="viewlarger" href="subbies/img1.jpg"><img src="subbies/img1.jpg" alt="img1" width="150px" height="100px" /></a><br />
hover to enlarge<br />
Line 2<br />
Line 3<br />
</p>
<div id="tooltip1">
<img src="subbies/img1.jpg" alt="img1" />
</div>
</body>
</html>