精华内容
下载资源
问答
  • 摘要:脚本资源,Ajax/JavaScript,缩略图,jquery滑动效果 Thumbnails Preview Slider with jQuery,一种基于jquery的缩略图滑动效果,鼠标放在小圆点上,缩略图即刻出现,有淡入淡出风格,有滑出风格,可应用于Js幻灯...
  • flash 右侧 缩略图 滑动 图片 广告
  • 一个完整的图像显示效果与花式缩略图滑动
  • CSS3缩略图滑动相册图片切换所属专题相册代码
  • jquery焦点图缩略图文字滑动菜单,供大家一起共同分享学习。
  • jQuery可预览缩略图滑动插件
  • JQuery带缩略图图片左右滑动切换是一款jQuery带缩略图按钮控制图片左右滑动切换代码。
  • 摘要:脚本资源,CSS特效,CSS3,滑动相册 纯CSS3实现的带缩略图滑动相册,带有缩略图显示,带有动态切换效果,简单实用。测试请注意,IE8不支持CSS3的部分属性,因此若使用IE可能会看不到滑动效果,而且网页出错,请...
  • jQuery幻灯片带缩略图平移滑动焦点图
  • 这是一款扁平风格的jQuery上下滑动缩略图字幕效果。当鼠标移动到缩略图上时,缩略图略微放大,说明字幕从下面滑动上来。
  • jquery点击缩略图片和背景图片滑动幻灯片
  • Vue图片滑动图库带有缩略图延迟加载和滑动的图片库
  • jquery slider图片滑动切换按钮和小缩略图控制大图片滑动切换
  • 前端JQuery插件,用于图片局部放大查看,模仿淘宝式图片放大镜。底部缩略图可点击左右按钮滑动进行切换
  • jQuery mobile滑动缩略图的新闻导航

    热门讨论 2012-12-16 16:32:10
    jQuery mobile滑动缩略图的新闻导航
  • jquery html5自适应滑动缩略图片自动分组 jquery html5自适应滑动缩略图片自动分组
  • 鼠标滑动翻页,垂直缩略图相册插件
  • jQuery带缩略图按钮控制图片左右滑动切换代码
  • 解压密码:RJ4587 这是一款支持鼠标拖拽的jQuery相册插件,这款jQuery相册的特点是右侧有一排垂直的缩略图,可以定义任意数量的图片,并且可以使用鼠标拖拽来对缩略图进行翻页浏览。另外,相册的图片切换支持自动...
  • vue-preview 缩略图横向滑动插件

    千次阅读 2018-10-31 17:22:02
    注意:This plugin currently support vue2.5 and above 安装包:npm i vue-preview -S 安装插件: import VuePreview from 'vue-preview' // defalut install Vue.use(VuePreview) // with parameters ...
    注意:This plugin currently support vue2.5 and above
    1. 安装包:npm i vue-preview -S
    2. 安装插件:
    import VuePreview from 'vue-preview'
     
    // defalut install
    Vue.use(VuePreview)
     
    // with parameters install
    Vue.use(preview, {
      mainClass: 'pswp--minimal--dark',
      barsSize: {top: 0, bottom: 0},
      captionEl: false,
      fullscreenEl: false,
      shareEl: false,
      bgOpacity: 0.85,
      tapToClose: true,
      tapToToggleControls: false
    })
    
    1. 引用实例:
    <template>
      <vue-preview :slides="slide1" @close="handleClose"></vue-preview>
    </template>
     
    <script>
    export default {
        data () {
          return {
            slide1: [
              {
                src: 'https://farm6.staticflickr.com/5591/15008867125_68a8ed88cc_b.jpg',
                msrc: 'https://farm6.staticflickr.com/5591/15008867125_68a8ed88cc_m.jpg',
                alt: 'picture1',
                title: 'Image Caption 1',
                w: 600,
                h: 400
              },
              {
                src: 'https://farm4.staticflickr.com/3902/14985871946_86abb8c56f_b.jpg',
                msrc: 'https://farm4.staticflickr.com/3902/14985871946_86abb8c56f_m.jpg',
                alt: 'picture2',
                title: 'Image Caption 2',
                w: 1200,
                h: 900
              }
            ]
          }
        },
        methods: {
          handleClose () {
            console.log('close event')
          }
        }
      }
    </script> 
    

    slide item options

    PropertyDescription
    srcmain (large) image
    msrcsmall image
    altimage replacement text
    wimage width
    himage height

    Events

    Event nameDescriptionparameter
    closeclose gallerynothing

    官网:vue-preview

    展开全文
  • 首先看下效果图, 主要功能分为3大块 一是滑动查看,通过viewpage来实现,方法见 ... 三、下方的缩略图,横向的listview来完成 点击放大用第三方控件PhotoViewAttacher,支持手指缩放,核心代码 ImageV...

    首先看下效果图,

    主要功能分为3大块

         一是滑动查看,通过viewpage来实现,方法见 http://www.cnblogs.com/lovemo1314/p/6109312.html

         二、点击放大

         三、下方的缩略图,横向的listview来完成

         点击放大用第三方控件PhotoViewAttacher,支持手指缩放,核心代码

    ImageView iv = new ImageView(this);
                Bitmap bitmap = WebchatAdapter.bitmaps.get(i);
                iv.setImageBitmap(bitmap);
    
                //放大及监听
                iv.setScaleType(ImageView.ScaleType.MATRIX);
                // 这句代码之前必须要现有默认图片来撑开位置
                iv.setOnClickListener(this);
                new PhotoViewAttacher(iv); //NOSON

          缩略图采用横向listview, 关于这个控件的资料网上许多地方都有介绍,比如 http://rensanning.iteye.com/blog/2201789

    这个控件使用起来很简单,只是把它当作纵向kistview来看就行,需要注意的是,listitem的图片布局必须指定固定的宽高,不然会出现一屏只出现一个缩略图的情况。

    首先看横向listview的适配器

    public class ThumbnailHorizontalLvAdapter extends MyBaseAdapter<FlagBitmap> {
        private Context mContext;
        private LayoutInflater mInflater;
        private int pre_position;
    
        public ThumbnailHorizontalLvAdapter(Context context) {
            super();
            mContext = context;
            mInflater = LayoutInflater.from(context);
        }
    
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {
            if (convertView == null) {
                convertView = mInflater.inflate(R.layout.listitem_thumbnail_horizontal, null);
            }
            ImageView thumbnailImgView = ViewHolder.getView(convertView, R.id.iv_thumbnail_img);
            LinearLayout container = ViewHolder.getView(convertView, R.id.ll_item_container);
    
            FlagBitmap srcBmp = getItem(position);
    
            thumbnailImgView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            thumbnailImgView.setImageBitmap(srcBmp.getBitmap());
    
            if (srcBmp.isSelected()){
                thumbnailImgView.setSelected(true);
                setViewHeightAndWidth(thumbnailImgView, UnitUtil.dp2Px(mContext,40),UnitUtil.dp2Px(mContext,40));
                setPadding(container,UnitUtil.dp2Px(mContext,6), UnitUtil.dp2Px(mContext,6));
            }else {
                thumbnailImgView.setSelected(false);
                setViewHeightAndWidth(thumbnailImgView, UnitUtil.dp2Px(mContext,30),UnitUtil.dp2Px(mContext,30));
                setPadding(container,UnitUtil.dp2Px(mContext,3), UnitUtil.dp2Px(mContext,11));
            }
            return convertView;
        }
    
        public void setSelectImg(int pos) {
            if (pos != pre_position){
                getItem(pos).setSelected(true);
                getItem(pre_position).setSelected(false);
                pre_position = pos;
                notifyDataSetChanged();
            }
        }
    
        public void initSelectImgPosition(int pos){
            pre_position = pos;
        }
        private void setViewHeightAndWidth(View v, float w, float h){
            ViewGroup.LayoutParams lp = v.getLayoutParams();
            lp.width = (int) w;
            lp.height = (int) h;
            v.setLayoutParams(lp);
        }
    
        private void setPadding(View v, float left, float top){
            v.setPadding((int)left,(int)top,(int)left,(int)top);
        }
    
        private Bitmap getPropThumnail(Bitmap bm) {
    //      Bitmap bb = BitmapUtil.getRoundedCornerBitmap(b, 100);
    //        int w = mContext.getResources().getDimensionPixelOffset(R.dimen.thumnail_default_width);
    //        int h = mContext.getResources().getDimensionPixelSize(R.dimen.thumnail_default_height);
    
    //        Bitmap thumBitmap = ThumbnailUtils.extractThumbnail(b, (int) UnitUtil.dp2Px(mContext, 100),
    //                (int) UnitUtil.dp2Px(mContext, 100));
    
            // 获得图片的宽高
            int width = bm.getWidth();
            int height = bm.getHeight();
            // 设置想要的大小
            int newWidth = 100;
            int newHeight = 100;
            // 计算缩放比例
            float scaleWidth = ((float) newWidth) / width;
            float scaleHeight = ((float) newHeight) / height;
            float scale = scaleHeight > scaleWidth ? scaleHeight : scaleWidth;
            // 取得想要缩放的matrix参数
            Matrix matrix = new Matrix();
            matrix.postScale(scale, scale);
            // 得到新的图片
            Bitmap newbm = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, true);
            Bitmap thumBitmap = ThumbnailUtils.extractThumbnail(newbm, (int) UnitUtil.dp2Px(mContext, 100),
                    (int) UnitUtil.dp2Px(mContext, 100));
    
            return newbm;
        }
    
    }

    MyBaseAdapter.java是我封装的一个适配器的基本模板,在这就不贴出来占空间了,很显然,在上面的代码中我们只重写了getview方法,这才是我们关注的重点,是不是完全与普通的list一样。由于在选中大图后,缩略图要随动更新显示,被选中的图要放大一点,带绿色边框。我这里的思路是通过selector器来实现带绿包边框的效果,而放大的效果则只需把对应的item的imageview宽高设置成比未选中的图片稍大一点,让图片来适配控件。

    先来看看listitem的布局,很简单,一个固定宽高的imageview

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ll_item_container"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    
        <ImageView
            android:id="@+id/iv_thumbnail_img"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:padding="2dp"
            android:background="@drawable/sel_thumbnail_img"
            android:src="@drawable/ico_customer_service" />
    </LinearLayout>

    再来看看图片的背景选择器文件

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
    
        <item android:drawable="@drawable/draw_thumbnail_sel_bg" android:state_selected="true" />
        <item android:drawable="@drawable/draw_thumbnail_unsel_bg" android:state_selected="false" />
    
    </selector>

    选中状态的draw_thumbnail_sel_bg.xml

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      ~ Copyright (c) 2015. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
      ~ Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
      ~ Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
      ~ Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
      ~ Vestibulum commodo. Ut rhoncus gravida arcu.
      -->
    
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- 连框颜色值 -->
        <item>
            <shape>
                <solid android:color="@color/bar_tint"/>
                <corners android:radius="5dp"/>
                <size android:width="40dp" android:height="40dp"></size>
            </shape>
        </item>
        <!-- 主体背景颜色值 -->
        <item
            android:bottom="2dp"
            android:left="2dp"
            android:right="2dp"
            android:top="2dp">
            <!--边框里面背景颜色 白色-->
            <shape>
                <corners android:radius="5dp"/>
                <solid android:color="@android:color/white"/>
            </shape>
        </item>
    </layer-list>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <!-- 连框颜色值 -->
        <item>
            <shape>
                <solid android:color="@color/line_back"/>
                <corners android:radius="5dp"/>
                <size android:width="30dp" android:height="30dp"></size>
            </shape>
        </item>
        <!-- 主体背景颜色值 -->
        <item
            android:bottom="0dp"
            android:left="0dp"
            android:right="0dp"
            android:top="0dp">
            <!--边框里面背景颜色 白色-->
            <shape>
                <corners android:radius="5dp"/>
                <solid android:color="@android:color/white"/>
            </shape>
        </item>
    </layer-list>

    最后只要把横向listview与viewpage中的大图关联起来就好了。

    //缩略图
            thumbnailHorizontalLvAdapter = new ThumbnailHorizontalLvAdapter(this);
            horizontalListView.setAdapter(thumbnailHorizontalLvAdapter);
            horizontalListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    viewPager.setCurrentItem(position);   //缩略图点击后同时刷新大图位置
                    thumbnailHorizontalLvAdapter.setSelectImg(position);
                }
            });

    再看大图的适配器

    public class KnowcognoViewImagePagerAdapter extends PagerAdapter implements ViewPager.OnPageChangeListener {
        private static final String TAG = "state-viewpage-know";
        private Context context;
        private ViewPager viewPager;
        private List<ImageView> views;
    
        private ThumbnailHorizontalLvAdapter thumbnailImgAdapter;
    
        public KnowcognoViewImagePagerAdapter(Context context, List<ImageView> viewpages, ViewPager viewPager, ThumbnailHorizontalLvAdapter thumbnailHorizontalLvAdapter) {
            this.context = context;
            this.viewPager = viewPager;
            thumbnailImgAdapter = thumbnailHorizontalLvAdapter;
    
            this.viewPager.addOnPageChangeListener(this);
            views = viewpages;
        }
    
        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            ImageView imageView = (ImageView) views.get(position);
            container.addView(imageView);
            return imageView;
        }
    
        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    
        @Override
        public int getCount() {
            return views.size();
        }
    
        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }
    
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }
    
        @Override
        public void onPageSelected(final int position) {
        }
    
        @Override
        public void onPageScrollStateChanged(int state) {
            System.err.println("-------state------>" + state);
            switch (state) {
                //在滚动完成之后
                case ViewPager.SCROLL_STATE_IDLE:
                    System.err.println("-------state-vitem----->" + viewPager.getCurrentItem());
                    thumbnailImgAdapter.setSelectImg(viewPager.getCurrentItem());  //滑动完,更新缩略图位置
                    break;
            }
        }
    }

    最后看横向listview的控件,这个也可以去网上找

    /*
     * HorizontalListView.java v1.5
     *
     * 
     * The MIT License
     * Copyright (c) 2011 Paul Soucy (paul@dev-smart.com)
     * 
     * Permission is hereby granted, free of charge, to any person obtaining a copy
     * of this software and associated documentation files (the "Software"), to deal
     * in the Software without restriction, including without limitation the rights
     * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     * copies of the Software, and to permit persons to whom the Software is
     * furnished to do so, subject to the following conditions:
     * 
     * The above copyright notice and this permission notice shall be included in
     * all copies or substantial portions of the Software.
     * 
     * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
     * THE SOFTWARE.
     *
     */
    
    
    import java.util.LinkedList;
    import java.util.Queue;
    
    import android.content.Context;
    import android.database.DataSetObserver;
    import android.graphics.PointF;
    import android.graphics.Rect;
    import android.os.Handler;
    import android.os.Message;
    import android.os.SystemClock;
    import android.util.AttributeSet;
    import android.view.GestureDetector;
    import android.view.GestureDetector.OnGestureListener;
    import android.view.MotionEvent;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.ListAdapter;
    import android.widget.Scroller;
    public class HorizontalListView extends AdapterView<ListAdapter> {
    
        protected ListAdapter mAdapter;
        private int mLeftViewIndex = -1;
        private int mRightViewIndex = 0;
        protected int mCurrentX;
        protected int mNextX;
        private int mMaxX = Integer.MAX_VALUE;
        private int mDisplayOffset = 0;
        protected Scroller mScroller;
        private GestureDetector mGesture;
        private Queue<View> mRemovedViewQueue = new LinkedList<View>();
        private OnItemSelectedListener mOnItemSelected;
        private OnItemClickListener mOnItemClicked;
        private OnItemLongClickListener mOnItemLongClicked;
        private boolean mDataChanged = false;
    
        private OnGestureMoveLinster mOnGestureMoveLinster;
        private LongClickMonitor mLongClickMonitor;
    
        public HorizontalListView(Context context) {
            super(context);
            initView();
        }
        public HorizontalListView(Context context, AttributeSet attrs) {
            super(context, attrs);
            initView();
        }
        public HorizontalListView(Context context, AttributeSet attrs, int styleid ) {
            super(context, attrs, styleid);
            initView();
        }
    
        private synchronized void initView() {
            mLeftViewIndex = -1;
            mRightViewIndex = 0;
            mDisplayOffset = 0;
            mCurrentX = 0;
            mNextX = 0;
            mMaxX = Integer.MAX_VALUE;
            mScroller = new Scroller(getContext());
            mGesture = new GestureDetector(getContext(), mOnGesture);
            mLongClickMonitor = new LongClickMonitor();
        }
        
        @Override
        public void setOnItemSelectedListener(OnItemSelectedListener listener) {
            mOnItemSelected = listener;
        }
        
        @Override
        public void setOnItemClickListener(OnItemClickListener listener){
            mOnItemClicked = listener;
        }
        
        @Override
        public void setOnItemLongClickListener(OnItemLongClickListener listener) {
            mOnItemLongClicked = listener;
        }
    
        private DataSetObserver mDataObserver = new DataSetObserver() {
    
            @Override
            public void onChanged() {
                synchronized(HorizontalListView.this){
                    mDataChanged = true;
                }
                invalidate();
                requestLayout();
            }
    
            @Override
            public void onInvalidated() {
                reset();
                invalidate();
                requestLayout();
            }
        };
    
        @Override
        public ListAdapter getAdapter() {
            return mAdapter;
        }
    
        @Override
        public View getSelectedView() {
            //TODO: implement
            return null;
        }
        public void setOnGestureMoveLinster( OnGestureMoveLinster linster ){
            this.mOnGestureMoveLinster = linster;
        }
        public void setMaxX( int max ){
            mMaxX = max;
        }
        //一次滑动一个对象的宽度
        private int bakWidth = 0;
        private int scrollWidth = 0;
        public void setScrollWidth( int width ){
            scrollWidth = width;
        }
    
        public void setNextX(int px){
            synchronized(HorizontalListView.this){
                mNextX = px;
            }
            requestLayout();
        }
    
        @Override
        public void setAdapter(ListAdapter adapter) {
            if(mAdapter != null) {
                mAdapter.unregisterDataSetObserver(mDataObserver);
            }
            mAdapter = adapter;
            mAdapter.registerDataSetObserver(mDataObserver);
            reset();
        }
        
        private synchronized void reset(){
            initView();
            removeAllViewsInLayout();
            requestLayout();
        }
    
        @Override
        public void setSelection(int position) {
            //TODO: implement
        }
        
        private void addAndMeasureChild(final View child, int viewPos) {
            LayoutParams params = child.getLayoutParams();
            if(params == null) {
                params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            }
    
            addViewInLayout(child, viewPos, params, true);
            child.measure(MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.AT_MOST),
                    MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.AT_MOST));
        }
    
        @Override
        protected synchronized void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
    
            if(mAdapter == null){
                return;
            }
    
            if(mDataChanged){
                int oldCurrentX = mCurrentX;
                initView();
                removeAllViewsInLayout();
                mNextX = oldCurrentX;
                mDataChanged = false;
            }
    
            if(mScroller.computeScrollOffset()){
                int scrollx = mScroller.getCurrX();
                mNextX = scrollx;
            }
    
            if(mNextX <= 0){
                mNextX = 0;
                mScroller.forceFinished(true);
    
            }
            if(mNextX >= mMaxX) {
                mNextX = mMaxX;
                mScroller.forceFinished(true);
            }
    
            int dx = mCurrentX - mNextX;
            
            removeNonVisibleItems(dx);
            fillList(dx);
            positionItems(dx);
            
            mCurrentX = mNextX;
            
            if(!mScroller.isFinished()){
                post(new Runnable(){
                    @Override
                    public void run() {
                        requestLayout();
                    }
                });
            }
        }
        
        private void fillList(final int dx) {
            int edge = 0;
            View child = getChildAt(getChildCount()-1);
            if(child != null) {
                edge = child.getRight();
            }
            fillListRight(edge, dx);
            
            edge = 0;
            child = getChildAt(0);
            if(child != null) {
                edge = child.getLeft();
            }
            fillListLeft(edge, dx);
            
            
        }
        
        private void fillListRight(int rightEdge, final int dx) {
            while(rightEdge + dx < getWidth() && mRightViewIndex < mAdapter.getCount()) {
                
                View child = mAdapter.getView(mRightViewIndex, mRemovedViewQueue.poll(), this);
                addAndMeasureChild(child, -1);
                rightEdge += child.getMeasuredWidth();
                
                if(mRightViewIndex == mAdapter.getCount()-1) {
                    int bakMaxX = mCurrentX + rightEdge - getWidth();
                    if( mMaxX == Integer.MAX_VALUE || bakMaxX > mMaxX ){
                        mMaxX = bakMaxX;
                    }
                }
                
                if (mMaxX < 0) {
                    mMaxX = 0;
                }
                mRightViewIndex++;
            }
            
        }
        
        private void fillListLeft(int leftEdge, final int dx) {
            while(leftEdge + dx > 0 && mLeftViewIndex >= 0) {
                View child = mAdapter.getView(mLeftViewIndex, mRemovedViewQueue.poll(), this);
                addAndMeasureChild(child, 0);
                leftEdge -= child.getMeasuredWidth();
                mLeftViewIndex--;
                mDisplayOffset -= child.getMeasuredWidth();
            }
        }
        
        private void removeNonVisibleItems(final int dx) {
            View child = getChildAt(0);
            while(child != null && child.getRight() + dx <= 0) {
                mDisplayOffset += child.getMeasuredWidth();
                mRemovedViewQueue.offer(child);
                removeViewInLayout(child);
                mLeftViewIndex++;
                child = getChildAt(0);
                
            }
            
            child = getChildAt(getChildCount()-1);
            while(child != null && child.getLeft() + dx >= getWidth()) {
                mRemovedViewQueue.offer(child);
                removeViewInLayout(child);
                mRightViewIndex--;
                child = getChildAt(getChildCount()-1);
            }
        }
        
        private void positionItems(final int dx) {
            if(getChildCount() > 0){
                mDisplayOffset += dx;
                int left = mDisplayOffset;
                for(int i=0;i<getChildCount();i++){
                    View child = getChildAt(i);
                    int childWidth = child.getMeasuredWidth();
                    child.layout(left, 0, left + childWidth, child.getMeasuredHeight());
                    left += childWidth + child.getPaddingRight();
                }
            }
        }
    
        private boolean bOnLongPress = false;
        @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
            if( !bOnLongPress && scrollWidth != 0 ){
                comsumeTouchEvent( ev );
                return true;
            }else{
                if( bOnLongPress && ev.getAction() == MotionEvent.ACTION_UP ){
                    bOnLongPress = false;
                    if(mOnGestureMoveLinster!=null && mOnGestureMoveLinster.moveend()){
                        return true;
                    }
                }
                if( bOnLongPress && !mOnGestureMoveLinster.canmove() )
                    return true;
                boolean handled = super.dispatchTouchEvent(ev);
                handled |= mGesture.onTouchEvent(ev);
                return handled;
            }
        }
    
        /** 用于记录开始时候的坐标位置 */
        private PointF startPoint = new PointF();
        private long startPressTime = 0;
        private boolean move_status = false;
        public boolean comsumeTouchEvent(MotionEvent event) {
            switch (event.getActionMasked()) {
    
                case MotionEvent.ACTION_DOWN:{
                    //AppLog.d(" MoveImageView onTouchEvent ACTION_DOWN ");
                    startPoint.set(event.getRawX(), event.getRawY());
                    bakWidth = 0;
                    move_status = false;
                    mLongClickMonitor.start();
                    startPressTime = System.currentTimeMillis();
                    break;
                }
                case MotionEvent.ACTION_MOVE:{
                    //AppLog.d(" MoveImageView onTouchEvent ACTION_MOVE ");
    
                    float dx = event.getRawX() - startPoint.x; // 得到x轴的移动距离
                    float dy = event.getRawY() - startPoint.y; // 得到x轴的移动距离
                    //避免和双击冲突,大于10f才算是拖动
                    if(Math.abs(dx) < 40){
                        break;
                    }
                    move_status = true;
                    if( bakWidth == 0 || bakWidth + ((int)dx) > scrollWidth || bakWidth + ((int)dx) < -scrollWidth ){
                        bakWidth = (int)dx;
                        if( mNextX == 0 ){
                            int distance = scrollWidth - scrollWidth/8;
                            mNextX += dx>0?-distance:distance;
                        }else if(mNextX >=mMaxX){
                            int distance = scrollWidth - scrollWidth/8;
                            mNextX += dx>0?-distance:distance;
                        }else{
                            int distance = scrollWidth;
                            mNextX += dx>0?-distance:distance;
                        }
                        requestLayout();
                    }else{
                        bakWidth += (int)dx;
                    }
                    startPoint.set(event.getRawX(), event.getRawY());
                }
                break;
                case MotionEvent.ACTION_UP: {
                    mLongClickMonitor.stop();
                    if( !move_status ){
                        if( System.currentTimeMillis() - startPressTime < 300 ){      //300ms
                            onClick();
                        }
                    }
                    move_status = false;
                    //AppLog.d(" MoveImageView onTouchEvent ACTION_UP ");
                    break;
                }
                default:
                    break;
            }
            return true;
        }
    
        protected boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                    float velocityY) {
            synchronized(HorizontalListView.this){
                mScroller.fling(mNextX, 0, (int)-velocityX, 0, 0, mMaxX, 0, 0);
            }
            requestLayout();
            
            return true;
        }
        
        protected boolean onDown(MotionEvent e) {
            mScroller.forceFinished(true);
            return true;
        }
        
        private OnGestureListener mOnGesture = new GestureDetector.SimpleOnGestureListener() {
    
            @Override
            public boolean onDown(MotionEvent e) {
                return HorizontalListView.this.onDown(e);
            }
    
            @Override
            public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                    float velocityY) {
                return HorizontalListView.this.onFling(e1, e2, velocityX, velocityY);
            }
    
            @Override
            public boolean onScroll(MotionEvent e1, MotionEvent e2,
                    float distanceX, float distanceY) {
                if( mOnGestureMoveLinster!=null && mOnGestureMoveLinster.moveby( -distanceX, -distanceY ) ){
                    return true;
                }
                mNextX += (int)distanceX;
                requestLayout();
                return true;
            }
    
            @Override
            public boolean onSingleTapConfirmed(MotionEvent e) {
    
                for(int i=0;i<getChildCount();i++){
                    View child = getChildAt(i);
                    if (isEventWithinView(e, child)) {
                        if(mOnItemClicked != null){
                            mOnItemClicked.onItemClick(HorizontalListView.this, child, mLeftViewIndex + 1 + i, mAdapter.getItemId( mLeftViewIndex + 1 + i ));
                        }
                        if(mOnItemSelected != null){
                            mOnItemSelected.onItemSelected(HorizontalListView.this, child, mLeftViewIndex + 1 + i, mAdapter.getItemId( mLeftViewIndex + 1 + i ));
                        }
                        break;
                    }
                    
                }
                return true;
            }
            
            @Override
            public void onLongPress(MotionEvent e) {
                int childCount = getChildCount();
                for (int i = 0; i < childCount; i++) {
                    View child = getChildAt(i);
                    if (isEventWithinView(e, child)) {
                        if (mOnItemLongClicked != null) {
                            bOnLongPress = true;
                            mOnItemLongClicked.onItemLongClick(HorizontalListView.this, child, mLeftViewIndex + 1 + i, mAdapter.getItemId(mLeftViewIndex + 1 + i));
                        }
                        break;
                    }
                }
            }
    
    
        };
    
        private boolean isEventWithinView(MotionEvent e, View child) {
            return isEventWithinView(  e.getRawX(), e.getRawY(),child );
        }
        private boolean isEventWithinView(  float x, float y, View child) {
    
            if( scrollWidth!=0 ){
                if( x < scrollWidth/8 || x > scrollWidth*9/8 )
                    return false;
            }
    
            Rect viewRect = new Rect();
            int[] childPosition = new int[2];
            child.getLocationOnScreen(childPosition);
            int left = childPosition[0];
            int right = left + child.getWidth();
            int top = childPosition[1];
            int bottom = top + child.getHeight();
            viewRect.set(left, top, right, bottom);
            return viewRect.contains( (int)x, (int)y );
        }
    
        public interface OnGestureMoveLinster{
            //返回true 消费事件了
            boolean moveby( float dx, float dy );
            boolean moveend();
            boolean canmove();
        }
    
        private static final int MSG_LONG = 1;
        private Handler handler = new Handler(){
            @Override
            public void handleMessage(Message msg) {
                switch ( msg.what ) {
                    case MSG_LONG:
                        onLongClick();
                        break;
                }
            }
        };
    
        class LongClickMonitor {
    
            private final int ST_RUN    = 1;
            private final int ST_STOP   = 0;
    
            private int run_status = ST_STOP;
    
            public LongClickMonitor(){
            }
    
            public void start(){
                if( run_status==ST_RUN ) return;
    
                run_status = ST_RUN;
                startRun();
            }
    
            public void stop(){
                if( run_status == ST_RUN ){
                    run_status = ST_STOP;
                }
            }
    
            public void startRun() {
                new Thread(new Runnable() {
                    @Override
                    public void run() {
    
                        while( run_status == ST_RUN ){
                            SystemClock.sleep(10);
                            if( System.currentTimeMillis() - startPressTime >= 1000 ){      //3S
                                handler.sendEmptyMessage( MSG_LONG );
                                break;
                            }
                        }
                        run_status = ST_STOP;
                    }
                }).start();
            }
        }
        private void onLongClick(){
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                if (isEventWithinView( startPoint.x, startPoint.y, child)) {
                    if (mOnItemLongClicked != null) {
                        bOnLongPress = true;
                        mOnItemLongClicked.onItemLongClick(HorizontalListView.this, child, mLeftViewIndex + 1 + i, mAdapter.getItemId(mLeftViewIndex + 1 + i));
                    }
                    break;
                }
            }
        }
    
        private void onClick(){
            for(int i=0;i<getChildCount();i++){
                View child = getChildAt(i);
                if (isEventWithinView( startPoint.x, startPoint.y, child)) {
                    if(mOnItemClicked != null){
                        mOnItemClicked.onItemClick(HorizontalListView.this, child, mLeftViewIndex + 1 + i, mAdapter.getItemId( mLeftViewIndex + 1 + i ));
                    }
                    if(mOnItemSelected != null){
                        mOnItemSelected.onItemSelected(HorizontalListView.this, child, mLeftViewIndex + 1 + i, mAdapter.getItemId( mLeftViewIndex + 1 + i ));
                    }
                    break;
                }
            }
        }
    
    }

     

    转载于:https://www.cnblogs.com/lovemo1314/p/6110339.html

    展开全文
  • 缩略图联动

    2018-06-19 09:12:58
    缩略图小图的集合点击加载出大图,随着viewpager的滑动。联动的效果
  • 包括延迟(智能)加载(适合移动设备)和缩略图。 演示版 安装 npm install --save vue-picture-swipe 用法 您可以根据需要使用它。 如果您想内联使用它,也可以在.vue文件组件中甚至使用Laravel使用以下示例。 ...
  • 缩略图预览大图并且可以左右滑动

    千次阅读 2016-05-05 15:17:49
    /*--------------------------------------------------------------------------------------------- @author Constantin Saguin - @brutaldesign @link http://csag.co @github http://g
    /*---------------------------------------------------------------------------------------------
    
    @author       Constantin Saguin - @brutaldesign
    @link            http://csag.co
    @github        http://github.com/brutaldesign/swipebox
    @version     1.2.1
    @license      MIT License
    
    ----------------------------------------------------------------------------------------------*/
    
    ;
    (function(window, document, $, undefined) {
    
    	$.swipebox = function(elem, options) {
    
    		var defaults = {
    			useCSS : true,
    			initialIndexOnArray : 0,
    			hideBarsDelay : 3000,
    			videoMaxWidth : 1140,
    			vimeoColor : 'CCCCCC',
    			beforeOpen : null,
    			afterClose : null
    		},
    
    		plugin = this, elements = [], // slides array [{href:'...',
    		// title:'...'}, ...],
    		elem = elem, selector = elem.selector, $selector = $(selector), isTouch = document.createTouch !== undefined
    				|| ('ontouchstart' in window)
    				|| ('onmsgesturechange' in window)
    				|| navigator.msMaxTouchPoints, supportSVG = !!(window.SVGSVGElement), winWidth = window.innerWidth
    				? window.innerWidth
    				: $(window).width(), winHeight = window.innerHeight
    				? window.innerHeight
    				: $(window).height(), html = '<div id="swipebox-overlay">\
    				<div id="swipebox-slider"></div>\
    				<div id="swipebox-action">\
    					<a id="swipebox-prev"></a>\
    					<a id="swipebox-next"></a>\
    					<a id="swipebox-close">关闭</a>\
    					<div class="scroll-page"><span class="curr-page">1</span><span>/</span><span class="total-page">5</span>\
        </div>\
    				</div>\
    		</div>';
    
    		plugin.settings = {}
    
    		plugin.init = function() {
    
    			plugin.settings = $.extend({}, defaults, options);
    
    			if ($.isArray(elem)) {
    
    				elements = elem;
    				ui.target = $(window);
    				ui.init(plugin.settings.initialIndexOnArray);
    
    			} else {
    
    				$selector.click(function(e) {
    							elements = [];
    							var index, relType, relVal;
    
    							if (!relVal) {
    								relType = 'rel';
    								relVal = $(this).attr(relType);
    							}
    
    							if (relVal && relVal !== ''
    									&& relVal !== 'nofollow') {
    								$elem = $selector.filter('[' + relType + '="'
    										+ relVal + '"]');
    							} else {
    								$elem = $(selector);
    							}
    
    							$elem.each(function() {
    
    										var title = null, href = null;
    
    										if ($(this).attr('title'))
    											title = $(this).attr('title');
    
    										if ($(this).attr('href'))
    											href = $(this).attr('href');
    
    										elements.push({
    													href : href,
    													title : title
    												});
    									});
    
    							index = $elem.index($(this));
    							e.preventDefault();
    							e.stopPropagation();
    							ui.target = $(e.target);
    							ui.init(index);
    						});
    			}
    		}
    
    		plugin.refresh = function() {
    			if (!$.isArray(elem)) {
    				ui.destroy();
    				$elem = $(selector);
    				ui.actions();
    			}
    		}
    
    		var ui = {
    
    			init : function(index) {
    				if (plugin.settings.beforeOpen)
    					plugin.settings.beforeOpen();
    				this.target.trigger('swipebox-start');
    				$.swipebox.isOpen = true;
    				this.build(index);
    				this.openSlide(index);
    				this.openMedia(index);
    				this.preloadMedia(index + 1);
    				this.preloadMedia(index - 1);
    			},
    
    			build : function(index) {
    				var $this = this;
    
    				$('body').append(html);
    				$("#swipebox-overlay").find(".curr-page").html(index + 1);
    				$("#swipebox-overlay").find(".total-page")
    						.html($selector.length);
    				if ($this.doCssTrans()) {
    					$('#swipebox-slider').css({
    								'-webkit-transition' : 'left 0.4s ease',
    								'-moz-transition' : 'left 0.4s ease',
    								'-o-transition' : 'left 0.4s ease',
    								'-khtml-transition' : 'left 0.4s ease',
    								'transition' : 'left 0.4s ease'
    							});
    					$('#swipebox-overlay').css({
    								'-webkit-transition' : 'opacity 1s ease',
    								'-moz-transition' : 'opacity 1s ease',
    								'-o-transition' : 'opacity 1s ease',
    								'-khtml-transition' : 'opacity 1s ease',
    								'transition' : 'opacity 1s ease'
    							});
    					$('#swipebox-action, #swipebox-caption').css({
    								'-webkit-transition' : '0.5s',
    								'-moz-transition' : '0.5s',
    								'-o-transition' : '0.5s',
    								'-khtml-transition' : '0.5s',
    								'transition' : '0.5s'
    							});
    				}
    				//图片等于一张的时候清除下方图片张数显示
            if (elements.length==1){
               $(".scroll-page").remove();
            }
    				/*
    				 * if(supportSVG){ var bg = $('#swipebox-action
    				 * #swipebox-close').css('background-image'); bg =
    				 * bg.replace('png', 'svg'); $('#swipebox-action
    				 * #swipebox-prev,#swipebox-action
    				 * #swipebox-next,#swipebox-action #swipebox-close').css({
    				 * 'background-image' : bg }); }
    				 */
    				$.each(elements, function() {
    							$('#swipebox-slider')
    									.append('<div class="slide"></div>');
    						});
    
    				$this.setDim();
    				$this.actions();
    				$this.keyboard();
    				$this.gesture();
    				$this.animBars();
    				$this.resize();
    
    			},
    
    			setDim : function() {
    
    				var width, height, sliderCss = {};
    
    				if ("onorientationchange" in window) {
    
    					window.addEventListener("orientationchange", function() {
    								if (window.orientation == 0) {
    									width = winWidth;
    									height = winHeight;
    								} else if (window.orientation == 90
    										|| window.orientation == -90) {
    									width = winHeight;
    									height = winWidth;
    								}
    							}, false);
    
    				} else {
    
    					width = window.innerWidth ? window.innerWidth : $(window)
    							.width();
    					height = window.innerHeight
    							? window.innerHeight
    							: $(window).height();
    				}
    
    				sliderCss = {
    					width : width,
    					height : height
    				}
    
    				$('#swipebox-overlay').css(sliderCss);
    
    			},
    
    			resize : function() {
    				var $this = this;
    
    				$(window).resize(function() {
    							$this.setDim();
    						}).resize();
    			},
    
    			supportTransition : function() {
    				var prefixes = 'transition WebkitTransition MozTransition OTransition msTransition KhtmlTransition'
    						.split(' ');
    				for (var i = 0; i < prefixes.length; i++) {
    					if (document.createElement('div').style[prefixes[i]] !== undefined) {
    						return prefixes[i];
    					}
    				}
    				return false;
    			},
    
    			doCssTrans : function() {
    				if (plugin.settings.useCSS && this.supportTransition()) {
    					return true;
    				}
    			},
    
    			gesture : function() {
    				if (isTouch) {
    					var $this = this, distance = null, swipMinDistance = 10, startCoords = {}, endCoords = {};
    					var bars = $('#swipebox-caption, #swipebox-action');
    
    					bars.addClass('visible-bars');
    					$this.setTimeout();
    
    					$('body').bind('touchstart', function(e) {
    
    						$(this).addClass('touching');
    
    						endCoords = e.originalEvent.targetTouches[0];
    						startCoords.pageX = e.originalEvent.targetTouches[0].pageX;
    
    						$('.touching').bind('touchmove', function(e) {
    									e.preventDefault();
    									e.stopPropagation();
    									endCoords = e.originalEvent.targetTouches[0];
    
    								});
    
    						return false;
    
    					}).bind('touchend', function(e) {
    						e.preventDefault();
    						e.stopPropagation();
    
    						distance = endCoords.pageX - startCoords.pageX;
    
    						if (distance >= swipMinDistance) {
    
    							// swipeLeft
    							$this.getPrev();
    
    						} else if (distance <= -swipMinDistance) {
    
    							// swipeRight
    							$this.getNext();
    
    						} else {
    							// tap
    							if (!bars.hasClass('visible-bars')) {
    								$this.showBars();
    								$this.setTimeout();
    							} else {
    								$this.clearTimeout();
    								$this.hideBars();
    							}
    
    						}
    
    						$('.touching').off('touchmove').removeClass('touching');
    
    					});
    
    				}
    			},
    
    			setTimeout : function() {
    				if (plugin.settings.hideBarsDelay > 0) {
    					var $this = this;
    					$this.clearTimeout();
    					$this.timeout = window.setTimeout(function() {
    								$this.hideBars()
    							}, plugin.settings.hideBarsDelay);
    				}
    			},
    
    			clearTimeout : function() {
    				window.clearTimeout(this.timeout);
    				this.timeout = null;
    			},
    
    			showBars : function() {
    				var bars = $('#swipebox-caption, #swipebox-action');
    				if (this.doCssTrans()) {
    					bars.addClass('visible-bars');
    				} else {
    					$('#swipebox-caption').animate({
    								top : 0
    							}, 500);
    					$('#swipebox-action').animate({
    								bottom : 0
    							}, 500);
    					setTimeout(function() {
    								bars.addClass('visible-bars');
    							}, 1000);
    				}
    			},
    
    			hideBars : function() {
    				var bars = $('#swipebox-caption, #swipebox-action');
    				if (this.doCssTrans()) {
    					bars.removeClass('visible-bars');
    				} else {
    					$('#swipebox-caption').animate({
    								top : '-50px'
    							}, 500);
    					$('#swipebox-action').animate({
    								bottom : '-50px'
    							}, 500);
    					setTimeout(function() {
    								bars.removeClass('visible-bars');
    							}, 1000);
    				}
    			},
    
    			animBars : function() {
    				var $this = this;
    				var bars = $('#swipebox-caption, #swipebox-action');
    
    				bars.addClass('visible-bars');
    				$this.setTimeout();
    
    				$('#swipebox-slider').click(function(e) {
    							if (!bars.hasClass('visible-bars')) { // 丢
    								$this.showBars();
    								$this.setTimeout();
    							}
    						});
    
    				$('#swipebox-action').hover(function() {
    							$this.showBars();
    							bars.addClass('force-visible-bars');
    							$this.clearTimeout();
    
    						}, function() {
    							bars.removeClass('force-visible-bars');
    							$this.setTimeout();
    
    						});
    			},
    
    			keyboard : function() {
    				var $this = this;
    				$(window).bind('keyup', function(e) {
    							e.preventDefault();
    							e.stopPropagation();
    							if (e.keyCode == 37) {
    								$this.getPrev();
    							} else if (e.keyCode == 39) {
    								$this.getNext();
    							} else if (e.keyCode == 27) {
    								$this.closeSlide();
    							}
    						});
    			},
    
    			actions : function() {
    				var $this = this;
    
    				if (elements.length < 2) {
    					$('#swipebox-prev, #swipebox-next').hide();
    				} else {
    					$('#swipebox-prev').bind('click touchend', function(e) {
    								e.preventDefault();
    								e.stopPropagation();
    								$this.getPrev();
    								$this.setTimeout();
    							});
    
    					$('#swipebox-next').bind('click touchend', function(e) {
    								e.preventDefault();
    								e.stopPropagation();
    								$this.getNext();
    								$this.setTimeout();
    							});
    				}
    
    				$('#swipebox-close').bind('click touchend', function(e) {
    							$this.closeSlide(); // 点击按钮关闭
    						});
    				$('.hiddd').bind('click touchend', function(e) {
    							$this.closeSlide(); // 点击图片关闭
    						});
    			},
    
    			setSlide : function(index, isFirst) {
    				isFirst = isFirst || false;
    
    				var slider = $('#swipebox-slider');
    
    				if (this.doCssTrans()) {
    					slider.css({
    								left : (-index * 100) + '%'
    							});
    				} else {
    					slider.animate({
    								left : (-index * 100) + '%'
    							});
    				}
    
    				$('#swipebox-slider .slide').removeClass('current');
    				$('#swipebox-slider .slide').eq(index).addClass('current');
    				this.setTitle(index);
    
    				if (isFirst) {
    					slider.fadeIn();
    				}
    
    				$('#swipebox-prev, #swipebox-next').removeClass('disabled');
    				if (index == 0) {
    					$('#swipebox-prev').addClass('disabled');
    				} else if (index == elements.length - 1) {
    					$('#swipebox-next').addClass('disabled');
    				}
    				$("#swipebox-overlay").find(".curr-page")
    						.html(index + 1);
    				$("#swipebox-overlay").find(".total-page")
    						.html($selector.length);
    			},
    
    			openSlide : function(index) {
    				$('html').addClass('swipebox');
    				$(window).trigger('resize'); // fix scroll bar visibility on
    				// desktop
    				this.setSlide(index, true);
    			},
    
    			preloadMedia : function(index) {
    				var $this = this, src = null;
    				if (elements[index] !== undefined)
    					src = elements[index].href;
    
    				if (!$this.isVideo(src)) {
    					setTimeout(function() {
    								$this.openMedia(index);
    							}, 1000);
    				} else {
    					$this.openMedia(index);
    				}
    			},
    
    			openMedia : function(index) {
    				var $this = this, src = null;
    
    				if (elements[index] !== undefined)
    					src = elements[index].href;
    				var currentIndex = index;
    				if (index < 0 || index >= elements.length) {
    					return false;
    				}
    
    				if (!$this.isVideo(src)) {
    					$this.loadMedia(src, function() {
    								$('#swipebox-slider .slide').eq(index)
    										.html(this);
    							});
    				} else {
    					$('#swipebox-slider .slide').eq(index).html($this
    							.getVideo(src));
    				}
    			},
    
    			setTitle : function(index, isFirst) {
    				var title = null;
    
    				$('#swipebox-caption').empty();
    
    				if (elements[index] !== undefined)
    					title = elements[index].title;
    
    				if (title) {
    					$('#swipebox-caption').append(title);
    				}
    			},
    
    			isVideo : function(src) {
    
    				if (src) {
    					if (src.match(/youtube\.com\/watch\?v=([a-zA-Z0-9\-_]+)/)
    							|| src.match(/vimeo\.com\/([0-9]*)/)) {
    						return true;
    					}
    				}
    
    			},
    
    			getVideo : function(url) {
    				var iframe = '';
    				var output = '';
    				var youtubeUrl = url.match(/watch\?v=([a-zA-Z0-9\-_]+)/);
    				var vimeoUrl = url.match(/vimeo\.com\/([0-9]*)/);
    				if (youtubeUrl) {
    
    					iframe = '<iframe width="560" height="315" src="//www.youtube.com/embed/'
    							+ youtubeUrl[1]
    							+ '" frameborder="0" allowfullscreen></iframe>';
    
    				} else if (vimeoUrl) {
    
    					iframe = '<iframe width="560" height="315"  src="http://player.vimeo.com/video/'
    							+ vimeoUrl[1]
    							+ '?byline=0&portrait=0&color='
    							+ plugin.settings.vimeoColor
    							+ '" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
    
    				}
    
    				return '<div class="swipebox-video-container" style="max-width:'
    						+ plugin.settings.videomaxWidth
    						+ 'px"><div class="swipebox-video">'
    						+ iframe
    						+ '</div></div>';
    			},
    
    			loadMedia : function(src, callback) {
    				if (!this.isVideo(src)) {
    					var img = $('<img>').on({
    								'load' : function() {
    
    									callback.call(img);
    								},
    								'click' : function() {
    
    								}
    							});
    
    					img.attr('src', src);
    				}
    			},
    
    			getNext : function() {
    				var $this = this;
    				index = $('#swipebox-slider .slide')
    						.index($('#swipebox-slider .slide.current'));
    				if (index + 1 < elements.length) {
    					index++;
    					$this.setSlide(index);
    					$this.preloadMedia(index + 1);
    				} else {
    
    					$('#swipebox-slider').addClass('rightSpring');
    					setTimeout(function() {
    								$('#swipebox-slider')
    										.removeClass('rightSpring');
    							}, 500);
    				}
    			},
    
    			getPrev : function() {
    				index = $('#swipebox-slider .slide')
    						.index($('#swipebox-slider .slide.current'));
    				if (index > 0) {
    					index--;
    					this.setSlide(index);
    					this.preloadMedia(index - 1);
    				} else {
    
    					$('#swipebox-slider').addClass('leftSpring');
    					setTimeout(function() {
    								$('#swipebox-slider').removeClass('leftSpring');
    							}, 500);
    				}
    			},
    
    			closeSlide : function() {
    				$('html').removeClass('swipebox');
    				$(window).trigger('resize');
    				this.destroy();
    			},
    
    			destroy : function() {
    				$(window).unbind('keyup');
    				$('body').unbind('touchstart');
    				$('body').unbind('touchmove');
    				$('body').unbind('touchend');
    				$('#swipebox-slider').unbind();
    				$('#swipebox-overlay').remove();
    				if (!$.isArray(elem))
    					elem.removeData('_swipebox');
    				if (this.target)
    					this.target.trigger('swipebox-destroy');
    				$.swipebox.isOpen = false;
    				if (plugin.settings.afterClose)
    					plugin.settings.afterClose();
    			}
    
    		};
    
    		plugin.init();
    
    	};
    
    	$.fn.swipebox = function(options) {
    		if (!$.data(this, "_swipebox")) {
    			var swipebox = new $.swipebox(this, options);
    			this.data('_swipebox', swipebox);
    		}
    		return this.data('_swipebox');
    	}
    
    }(window, document, jQuery));

    <!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0"/>
    <meta name="apple-mobile-web-app-capable" content="yes"/>
    <meta name="format-detection" content="telephone=no,email=no"/>
    <meta charset="UTF-8">
    <meta name="Generator" content="EditPlus®">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    <title>图片处理</title>
    <style type="text/css">
    * {margin:0;padding:0;-webkit-box-sizing:border-box;box-sizing:border-box;outline:0;-webkit-tap-highlight-color:transparent;}
    body { width: 100%;height: auto;margin: 0px auto;}
    a { display: block;  margin: 0;  padding:0;   text-align: center;  }
    a:link,a:visited{ text-decoration:none;  /*超链接无下划线*/ }
    span {display: block;}
    div { display: block; }
    #fakecrop-fill a { margin: 4px 4px 0 0;   }
    .container{ float: left; padding: 0 0 0 2%; width: 100%;}
    .container img{ vertical-align: top;}
    .scroll-page{ background-color:rgba(255,255,255,0.75);height: 25px; line-height: 25px; color: #000; border-radius: 4px; position: absolute;top: 15px; right: 42%; padding: 0 16px;}
    .scroll-page span{ text-shadow:none; color: #000; float:left;}
    #swipebox-action #swipebox-close{ background:#28a000;}
    #swipebox-action{bottom:0px !important; border-top:none !important; background:none !important;font-family:微软雅黑;}
    </style>
    <link href="css/swipebox.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="js/jquery-2.1.3.min.js"></script>
    <script type="text/javascript" src="js/jquery.fakecrop.js"></script>
    <script type="text/javascript" src="js/jquery.swipebox.js" ></script>
    </head>
    
    <body>
    <div  class="container" id="fakecrop-fill">
    	<a class="swipebox" href="images/1.jpg" style="float: left; overflow: hidden; width: 100px; height: 100px; position: relative;">
        	<img src="images/1.jpg" class="fc-init" style="display: inline; position: absolute; left: 0px; height: 177.5px; width: 100px;">
        </a>
        <a class="swipebox" href="images/2.jpg" style="float: left; overflow: hidden; width: 100px; height: 100px; position: relative;">
        	<img src="images/2.jpg" class="fc-init" style="display: inline; position: absolute; left: 0px; height: 177.5px; width: 100px;">
        </a>	
        <a class="swipebox" href="images/3.jpg" style="float: left; overflow: hidden; width: 100px; height: 100px; position: relative;">
        	<img src="images/3.jpg" class="fc-init" style="display: inline; position: absolute; left: 0px; height: 177.5px; width: 100px;">
        </a>		
    </div>
    <script>
    $(document).ready(function () {
    	$("#fakecrop-fill").html();
        $('#fakecrop-fill img').fakecrop();
        $(".swipebox").swipebox();
    });
    </script> 
    
    </body>
    </html>
    

    html.swipebox {
      overflow: hidden!important;
    }
    
    #swipebox-overlay img {
      border: none!important;
    }
    
    #swipebox-overlay {
      width: 100%;
      height: 100%;
      position: fixed;
      top: 0;
      left: 0;
      z-index: 99999!important;
      overflow: hidden;
      -webkit-user-select: none;
      -moz-user-select: none;
      user-select: none;
    }
    
    #swipebox-slider {
      height: 100%;
      left: 0;
      top: 0;
      width: 100%;
      white-space: nowrap;
      position: absolute;
      display: none;
    }
    
    #swipebox-slider .slide {
      /*background: url("img/loader.gif") no-repeat center center;*/
      height: 100%;
      width: 100%;
      line-height: 1px;
      text-align: center;
      display: inline-block;
    }
    
    #swipebox-slider .slide:before {
      content: "";
      display: inline-block;
      height: 50%;
      width: 1px;
      margin-right: -1px;
    }
    
    #swipebox-slider .slide img,
    #swipebox-slider .slide .swipebox-video-container {
      display: inline-block;
      margin: 0;
      padding: 0;
      width: 100%;
      height: auto;
      vertical-align: middle;
    }
    
    #swipebox-slider .slide .swipebox-video-container {
      background:none;
      max-width: 1140px;
      max-height: 100%;
      width: 100%;
      padding:5%;
      box-sizing: border-box;
      -webkit-box-sizing: border-box;
      -moz-box-sizing: border-box;
    }
    
    
    #swipebox-slider .slide .swipebox-video-container .swipebox-video{
      width: 100%;
      height: 0;
      padding-bottom: 56.25%;
      overflow: hidden;
      position: relative;
    }
    
    #swipebox-slider .slide .swipebox-video-container .swipebox-video iframe{
      width: 100%!important; 
      height: 100%!important;
      position: absolute;
      top: 0; left: 0;
    }
    
    #swipebox-action, #swipebox-caption {
      position: absolute;
      left: 0;
      z-index: 999;
      height: 55px;
      width: 100%;
    }
    
    #swipebox-action {
      bottom: -50px;
    }
    #swipebox-action.visible-bars {
      bottom: 0;
    }
    
    #swipebox-action.force-visible-bars {
      bottom: 0!important;
    }
    
    #swipebox-caption {
      top: -50px;
      text-align: center;
    }
    #swipebox-caption.visible-bars {
      top: 0;
    }
    
    #swipebox-caption.force-visible-bars {
      top: 0!important;
    }
    
    #swipebox-action #swipebox-prev, #swipebox-action #swipebox-next,
    #swipebox-action #swipebox-close {
      /*background-image: url("img/icons.png");
      background-repeat: no-repeat;*/
      border: none!important;
      text-decoration: none!important;
      cursor: pointer;
      position: absolute;
      width:60px;
      height:25px;
      bottom:15px;
      right:15px;
      color:#fff;
      text-align:center;
      line-height:25px;
       text-shadow:none;
        border-radius:4px;
    }
    
    #swipebox-action #swipebox-close {
     /* background-position: 15px 12px;*/
      right: 40px;
    }
    
    #swipebox-action #swipebox-prev {
      background-position: -32px 13px;
      /*right: 100px;*/
      left:40px;
    }
    
    #swipebox-action #swipebox-next {
      background-position: -78px 13px;
     /* right: 40px;*/
     left:100px;
    }
    
    #swipebox-action #swipebox-prev.disabled,
    #swipebox-action #swipebox-next.disabled {
      filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=30);
      opacity: 0.3;
    }
    
    #swipebox-slider.rightSpring {
      -moz-animation: rightSpring 0.3s;
      -webkit-animation: rightSpring 0.3s;
    }
    
    #swipebox-slider.leftSpring {
      -moz-animation: leftSpring 0.3s;
      -webkit-animation: leftSpring 0.3s;
    }
    
    @-moz-keyframes rightSpring {
      0% {
        margin-left: 0px;
      }
    
      50% {
        margin-left: -30px;
      }
    
      100% {
        margin-left: 0px;
      }
    }
    
    @-moz-keyframes leftSpring {
      0% {
        margin-left: 0px;
      }
    
      50% {
        margin-left: 30px;
      }
    
      100% {
        margin-left: 0px;
      }
    }
    
    @-webkit-keyframes rightSpring {
      0% {
        margin-left: 0px;
      }
    
      50% {
        margin-left: -30px;
      }
    
      100% {
        margin-left: 0px;
      }
    }
    
    @-webkit-keyframes leftSpring {
      0% {
        margin-left: 0px;
      }
    
      50% {
        margin-left: 30px;
      }
    
      100% {
        margin-left: 0px;
      }
    }
    
    @media screen and (max-width: 800px) {
      #swipebox-action #swipebox-close {
        /*left: 0;*/
    	right: 15px;
      }
    
      #swipebox-action #swipebox-prev {
        left: 0px;
      }
    
      #swipebox-action #swipebox-next {
        left:60px;
      }
    }
    
    
    /* Skin 
    --------------------------*/
    #swipebox-overlay {
      background: #0d0d0d;
    }
    
    #swipebox-action, #swipebox-caption {
      text-shadow: 1px 1px 1px black;
      background-color: #0d0d0d;
      background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(0%, #0d0d0d), color-stop(100%, #000000));
      background-image: -webkit-linear-gradient(#0d0d0d, #000000);
      background-image: -moz-linear-gradient(#0d0d0d, #000000);
      background-image: -o-linear-gradient(#0d0d0d, #000000);
      background-image: linear-gradient(#0d0d0d, #000000);
      filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=95);
      opacity: 0.95;
    }
    
    #swipebox-action {
      border-top: 1px solid rgba(255, 255, 255, 0.2);
    }
    
    #swipebox-caption {
      border-bottom: 1px solid rgba(255, 255, 255, 0.2);
      color: white!important;
      font-size: 15px;
      line-height: 43px;
      font-family: Helvetica, Arial, sans-serif;
    }
    
    

    /***
     * jquery.fakecrop.js
     * Copyright (c) 2012 Vuong Nguyen
     * http://vuongnguyen.com 
     */
    (function ($) {
    	var methods = {
    		ratio : function (args) {
    			var item = args.item,
    				settings = args.settings;
    			return { w : item.width()/settings.wrapperWidth, 
    					h : item.height()/settings.wrapperHeight };
    		},
    		center : function (long, short) {
    			return parseInt((long-short)/2, 10);
    		},
    		scaleToFill : function (args) {
    			var item = args.item,
    			settings = args.settings,
    			ratio = settings.ratio,
    			width = item.width(),
    			height = item.height(),
    			offset = {top: 0, left: 0};
    			
    			if (ratio.h > ratio.w) {
    				width = settings.wrapperWidth;
    				height = height / ratio.w;
    				if (settings.center) {
    					offset.top = methods.center(width, height);
    				}
    			} else {
    				height = settings.wrapperHeight;
    				width = width / ratio.h;
    				if (settings.center) {
    					offset.left = methods.center(height, width);
    				}
    			}
    			
    			if (settings.center) {
    				args.wrapper.css('position', 'relative');
    				item.css({
    					'position' : 'absolute',
    					'top' : ['-', offset.top, 'px'].join(''),
    					'left' : offset.left + 'px'
    				});
    			}
    			
    			return item.height(height).attr('height', height + 'px')
    						.width(width).attr('width', width + 'px');
    		},
    		scaleToFit : function (args) {
    			var item = args.item,
    				settings = args.settings,
    				ratio = settings.ratio,
    				width = item.width(),
    				height = item.height(),
    				offset = {top: 0, left: 0};
    			
    			if (ratio.h > ratio.w) {
    				height = settings.wrapperHeight,
    				width = parseInt((item.width() * settings.wrapperHeight)/item.height(), 10);
    				if (settings.center) {
    					offset.left = methods.center(height, width);
    				}
    			} else {
    				height = parseInt((item.height() * settings.wrapperWidth)/item.width(), 10),
    				width = settings.wrapperWidth;
    				if (settings.center) {
    					offset.top = methods.center(width, height);
    				}
    			}
    
    			args.wrapper.css({
    				'width' : (settings.squareWidth ? settings.wrapperWidth : width) + 'px',
    				'height' : settings.wrapperHeight + 'px'
    			});
    			
    			if (settings.center) {
    				args.wrapper.css('position', 'relative');
    				item.css({
    					'position' : 'absolute',
    					'top' : offset.top +'px',
    					'left' : offset.left + 'px'
    				});
    			}
    			return item.height(height).attr('height', height + 'px')
    						.width(width).attr('width', width + 'px');
    		},
    		init : function (options) {
    			var settings = $.extend({
    				wrapperSelector : null,
    				wrapperWidth : 100,
    				wrapperHeight : 100,
    				center : true,
    				fill : true,
    				initClass : 'fc-init',
    				doneEvent : 'fakedropdone',
    				squareWidth : true
    			}, options),
    			_init = function () {
    				var item = $(this),
    					wrapper = settings.wrapperSelector ? item.closest(settings.wrapperSelector) : item.parent(),
    					args = { item : item,
    							settings : settings,
    							wrapper : wrapper }; 
    					settings.ratio = methods.ratio(args);
    					if (settings.fill) {
    						wrapper.css({
    							'float' : 'left',
    							'overflow' : 'hidden',
    							'width' : settings.wrapperWidth + 'px',
    							'height' : settings.wrapperHeight + 'px'
    						});
    						methods.scaleToFill(args);
    					} else {
    						methods.scaleToFit(args);
    					}
    					
    					item.data('fc.settings', settings)
    						.addClass(settings.initClass) // Add class to container after initialization
    						.trigger(settings.doneEvent); // Publish an event to announce that fakecrop in initialized
    			},
    			images = this.filter('img'),
    			others = this.filter(':not(img)');
    			if (images.length) {
    				images.bind('load', function () {
    					_init.call(this);
    					this.style.display = 'inline';
    				}).each(function () {
    					// trick from paul irish's https://gist.github.com/797120/7176db676f1e0e20d7c23933f9fc655c2f120c58
    					if (this.complete || this.complete === undefined) {
    						var src = this.src;
    						this.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
    						this.src = src;
    						this.style.display = 'none';
    					}
    				});
    			}
    			if (others.length) {
    				others.each(_init);
    			}
    			return this;
    		}	
    	};
    	$.fn.fakecrop = function (method) {
    		if (methods[method]) {
    			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
    		} else if (typeof method === 'object' || !method) {
    			return methods.init.apply(this, arguments);
    		} else {
    			$.error('Method ' + method + ' does not exist on jQuery.fakecrop');
    		} 
    	};
    })(jQuery);

    之前做项目做到分享的时候,做过上传图片为缩略图模式,并且可以进行大图预览

    就用了fakecrop以及swipebox进行显示

    下面是我的代码:


    展开全文

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 7,343
精华内容 2,937
关键字:

缩略图滑动