0

How to dynamic set top css when element over top page or bottom page ?

First , mouse over first cat image. It's OK

http://image.ohozaa.com/i/480/7YpWei.jpg

When i scroll page to bottom and mouses first cat image again ,

http://image.ohozaa.com/i/5b5/l2l3dj.jpg

big cat image over top page

And When i scroll page to top and mouses 3 cat image again ,

http://image.ohozaa.com/i/5db/ezZE1b.jpg

big cat image over bottom page

How to change top css of mouse over effect element to not over top page or over bottom page ?

http://jsfiddle.net/L7Lyjtp7/

index.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>

<style type="text/css">
<?PHP
    for($i=0;$i<3;$i++)
    {
?>
        .top_box<?PHP echo $i; ?>{
        left: 99px;
        top: 0px;
        position: absolute;
        border: 1px solid #000;
display: none;
        }
<?PHP
    }
?>
</style>

<?PHP
    for($i=0;$i<3;$i++)
{
?>
<script type="text/javascript">
$(document).ready(function(){    
    $("#thumbnail<?PHP echo $i ; ?>").hover(
        function(){
            var id = $(this).data("id");
            if(id!==undefined){
             $("#" + id).show();   
            }
            $("#top_box<?PHP echo $i; ?>").show(); 

        },function(){
            $("#top_box<?PHP echo $i; ?>").hide(); 

        });
});
</script>
<?PHP
    }
?>
</head>

<br><br><br><br><br><br><br><br><br><br>
<div style=" float: left; position: relative; width: 100%; margin-bottom: 200px; " >
    <div id="top_box0" class="top_box0">
        <img src="http://consciouscat.net/wp-content/uploads/2010/02/cat-licks-lips-200px.jpg">
    </div>
    <span id="thumbnail0" style=" margin: 7px; position: relative;">
        <img border="0" src="http://consciouscat.net/wp-content/uploads/2010/02/cat-licks-lips-200px.jpg" width="80" height="80"/>                
    </span>
</div>
<br>
<div style=" float: left; position: relative; width: 100%; margin-bottom: 200px; " >
    <div id="top_box1" class="top_box1">
        <img src="http://cat-bounce.com/cb.png">
    </div>
    <span id="thumbnail1" style=" margin: 7px; position: relative; ">
        <img border="0" src="http://cat-bounce.com/cb.png" width="80" height="80"/>                  
    </span>
</div>
<br>
<div style=" float: left; position: relative; width: 100%; margin-bottom: 200px; " >
    <div id="top_box2" class="top_box2">
        <img src="http://media.yopi.co.th/prod_pics/12/e/12827.jpg">
    </div>
    <span id="thumbnail2" style=" margin: 7px; position: relative;">
        <img border="0" src="http://media.yopi.co.th/prod_pics/12/e/12827.jpg" width="80" height="80"/>                  
    </span>
</div>
nomwery geqoilu
  • 109
  • 2
  • 10

1 Answers1

0

You can set the CSS to fixed like so: JSFIDDLE However if you want the cats to appear next to the images you can add jquery to calculate if image is on "top page"/"bottom page" and set position fixed as needed.

.top_box0{
    left: 99px;
    top: 0px;
    position: fixed;
    border: 1px solid #000;
    display: none;
}
.top_box1{
    left: 99px;
    top: 0px;
    position: fixed;
    border: 1px solid #000;
    display: none;
}
.top_box2{
    left: 99px;
    top: 0px;
    position: fixed;
    border: 1px solid #000;
    display: none;
}
Adrian Forsius
  • 1,437
  • 2
  • 19
  • 29