zoukankan      html  css  js  c++  java
  • JS实现两张图片卷轴的切换效果

    效果参见: http://weitwo.com/home.htm 引入jQuery后,

    再引入如下JS:

    $(document).ready(function () {
        
    var slidePicture = new sliderPicture();
        slidePicture.containerId 
    = 'container';
        slidePicture.frontId 
    = 'front';
        slidePicture.minFrontWidth 
    = 100;
        slidePicture.load();
    });

    function sliderPicture() {
        
    this.containerId = '';
        
    this.frontId = '';
        
    this.minFrontWidth = 200;

        
    this.load = function () {

            
    var container = $('#' + this.containerId);
            
    var front = $('#' + this.frontId);
            
    var minWith = this.minFrontWidth;

            container.mousemove(
    function (e) {
                
    var offsetLeft = container.prop("offsetLeft");
                
    var parentWidth = container.prop("clientWidth");
                
    var left = e.clientX - offsetLeft; 
                
    var width = parentWidth - left;

                
    if (width >= minWith) {
                    front.width(width);
                }
            });
        }
    }

    添加如下样式:

    #container
    {
        background
    :url('http://photocdn.sohu.com/20110527/Img308750491.jpg');
        width
    :90%;
        height
    :200px;
        margin
    :0px auto;
    }
     
    #front
    {
        float
    :right;
        background
    :url('http://news3.xinhuanet.com/auto/2005-07/06/xinsrc_3520702061714562873521.jpg');
        background-position
    :right;
        width
    :30%;
        height
    :100%;
    }

    #splitter
    {
        background
    :#000000;
        height
    :100%;
        float
    :left;
        width
    :5px;
    }

    添加如下HTML:

    <div id="container">
        
    <div id="front">
            
    <span id="splitter"></span>
        
    </div>
      
    </div>

    即可实现图片卷轴的效果。

     

  • 相关阅读:
    OpenCV程序在生产环境中运行
    C#调用C++导出(dllexport)方法
    IIS7.5 GZip配置
    wcf学习笔记--初识wcf
    Greenplum installation guide
    Cloudera 5.8.2 Installation guide
    WPF DataGrid 合并单元格
    wpf DataGrid CheckBox列全选
    WPF button 圆角制作
    WPF passwordbox 圆角制作
  • 原文地址:https://www.cnblogs.com/hanxianlong/p/2079749.html
Copyright © 2011-2022 走看看