代码之家  ›  专栏  ›  技术社区  ›  aaandre

在图片上自定义带有prevpage和nextpage的可滚动插件?(见模型)

  •  1
  • aaandre  · 技术社区  · 16 年前

    我正在实现一个可滚动的投资组合画廊。

    (scrollable=scrollable插件来自 http://flowplayer.org/tools/index.html )

    一次只能看到一个项目。

    默认情况下,可滚动将上一个/下一个按钮放置在图像区域之外,单击当前图像将推进可滚动内容。

    1. 我想在图像区域内进行上一个/下一个渲染。
    2. 我想让一个图片标题出现时,鼠标在图像的下部。

    模型: http://i303.photobucket.com/albums/nn160/upstagephoto/mockups/scrollable_mockup.jpg

    对如何实现这两个目标有什么想法吗?

    谢谢您!

    2 回复  |  直到 16 年前
        1
  •  0
  •   Jakub Hampl    16 年前

    你的方法的主要部分在你的html中将是这样的:

    <div id="mainContainer">
      <div class="scrollable">
        <div class="items">
          <div class="scrollableEl">
             <img src="yourimage.jpg" />
             <div class="caption">Your caption</div>
          </div>
    
          <div class="scrollableEl">
             <img src="yourimage2.jpg" />
             <div class="caption">Your caption 2</div>
          </div>
    
          ... so on ...
        </div>
      </div>
      <a href="#" class="prev">&laquo;</a>
      <a href="#" class="prev">&laquo;</a>
    </div>
    

    就像你的css一样:

    .scrollable {
        position:relative;
        overflow:hidden;
        width: 660px;
        height:90px;
    }
    
    .scrollable .items {
        width:20000em;
        position:absolute;
    }
    
    .items .scrollableEl {
        float:left;
        positon: relative;
    }
    
    .items .scrollableEl .caption {
        display:none;
        position: absolute;
        bottom: 0;
        height: 100px;
        width: 660px;
    }
    
    .items .scrollableEl:hover .caption { /*this will show your caption on mouse over */
        display:none;
    }
    
    .next, .prev {
        position: absolute;
        top: 0;
        display: block;
        width: 30px;
        height: 100%;
    }
    .next {
        right: 0;
    }
    .prev {
        left: 0;
    }
    #mainContainer {
        position: relative;
    }
    

    javascript应该相当标准。希望这有帮助!

        2
  •  0
  •   Luca Filosofi    16 年前

    演示: http://jsbin.com/ijede/2 来源: http://jsbin.com/ijede/2/edit

    $(function() {
        // 5 minute slide show ;-)
        $('.next,.prev').click(function(e) {
            e.preventDefault();
            var pos = parseInt($('.current').attr('id').split('_')[1]);
            var tot = $('.slides a').size() - 1;
            var click = this.className;
            var new_pos = (click == 'next') ? pos + 1: pos - 1;
            var slide = ( click == 'next') ? 
                        (pos < tot ? true : false) : (pos > 0 ? true : false);
    
            if (slide) $('.current').toggle(500,function() {
              $(this).removeClass('current');
            });
            $('#pos_' + new_pos).toggle(500,function() {
                $(this).attr('class', 'current');
            });
        });
        //cross-browser div :hover
        $('.next,.prev').hover(function() {
          $(this).children().children().fadeIn(500);
        },function() {
          $(this).children().children().fadeOut(500);
        });
        //auto add unique id to each image
        $('.slides a').each(function(e) {
            $(this).attr('id', 'pos_' + e);
            if (!e) $(this).attr('class', 'current');
        });
    });​
    

    CSS 源头!

    注: 因为阅读插件文档比从头开始制作幻灯片需要更多的时间,所以我做了一个新的!

    希望你喜欢!

    推荐文章