滑动标题。根据图像大小将widget放在caption.resizing中

时间:2015-02-18 23:50:54

标签: javascript html css

我正在尝试获取带有两个字幕的图像。一个将从顶部向下滑动,一个将从底部向上滑动。我想得到它们相对于图像的大小(因此动态地改变到图像的大小),并且它们中的每一个都覆盖了图像的25%。

目前我有一个从左上方滑动,但我需要它从顶部向下滑动,底部的那个也从左侧滑动,但我需要它从底部滑动。

这是小提琴:http://jsfiddle.net/s4qvL5cf/1/

<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
    <title>review image system</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" media="screen" href="style.css" />
    <script src="modernizr.custom.js"></script>
    <script src="jquery.js"></script>
    <script src="newjavascript.js"></script>
    <script src="toucheffects.js"></script>
</head>

<body>
<div class="wrapper">

    <header>
        <h1 class="main_head">blub</h1>

    </header>
    <hr />

        <div class="container left">

            <img src="http://placehold.it/350x150" alt="image" />
            <article class="text css3-4">
                    <h1><a href="#" class="css3-4">space1</a></h1>
            </article>
            <article class="text css3-3 css3-4">
                    <h1><a href="#" class="css3-3 css3-4">space2</a>    </h1>
                    <span><div class='movie_choice'>
                                                            <div id="r1" class="rate_widget">
                                                           <div class="star_1 ratings_stars"></div>
                                                            <div class="star_2 ratings_stars"></div>
                                                            <div class="star_3 ratings_stars"></div>
                                                            <div class="star_4 ratings_stars"></div>
                                                             <div class="star_5 ratings_stars"></div>
                                                             <div class="total_votes">vote data</div>
                                                              </div>
                                                              </div>
                                                    </span>
            </article>
        </div>

    <hr />

    </div>  

    <script>


// first thing added 
$(document).ready(function() {

    $('.rate_widget').each(function(i) {
        var widget = this;
        var out_data = {
            widget_id : $(widget).attr('id'),
            fetch: 1
        };
        $.post({
            url:'ratings.php',
            data: out_data,
            success:function(INFO) {
                $(widget).data( 'fsr', INFO );
                set_votes(widget);
            },
            dataType:'json'
        });
    });


    $('.ratings_stars').hover(
        // Handles  mouseover
        function() {
            $(this).prevAll().andSelf().addClass('ratings_over');
            $(this).nextAll().removeClass('ratings_vote'); 
        },
        // Handles mouseout
        function() {
            $(this).prevAll().andSelf().removeClass('ratings_over');
            // can't use 'this' because it wont contain the updated data
            set_votes($(this).parent());
        }
    );


    //  records the vote
    $('.ratings_stars').bind('click', function() {
        var star = this;
        var widget = $(this).parent();

        var clicked_data = {
            clicked_on : $(star).attr('class'),
            widget_id : $(star).parent().attr('id')
        };
        $.post(
                {
            url:'ratings.php',
           data: clicked_data,
            success:function(INFO) {
                widget.data( 'fsr', INFO );
                set_votes(widget);
            },
            dataType:'json'
    });



});

function set_votes(widget) {

    var avg = $(widget).data('fsr').whole_avg;
    var votes = $(widget).data('fsr').number_votes;
    var exact = $(widget).data('fsr').dec_avg;

    window.console && console.log('and now in set_votes, it thinks the fsr is ' + $(widget).data('fsr').number_votes);

    $(widget).find('.star_' + avg).prevAll().andSelf().addClass('ratings_vote');
    $(widget).find('.star_' + avg).nextAll().removeClass('ratings_vote'); 
    $(widget).find('.total_votes').text( votes + ' votes recorded (' + exact + ' rating)' );
}

});
</script>

1 个答案:

答案 0 :(得分:0)

对于您需要的更改幻灯片,您需要更改css过渡,请参阅this

article.css3-3
{
    top:-80px;
    -webkit-transition: all .5s ease-out;
    -moz-transition: all .5s ease-out;
    -o-transition: all .5s ease-out;
    transition: all .5s ease-out;
    width:400px;
}

.container:hover article.css3-3 {
    top:0;
}

...

article.css3-4
{
    bottom:-80px;
    -webkit-transition: all .5s ease-out;
    -moz-transition: all .5s ease-out;
    -o-transition: all .5s ease-out;
    transition: all .5s ease-out;
    width:400px;
}

.container:hover article.css3-4{
    bottom:0;
}

我测试了删除元素“.container”的宽度和高度属性。我认为加载的图像会根据需要增加容器。 Take a look

.container {
    ...
    /*height: 200px;*/
    ...
}

.container2 {
    ...
    /*height: 200px;*/
    ...
}