js仿微信朋友圈图片切换展示特效



103 411 138



特效描述:js 仿微信朋友圈 图片切换展示, <p>js仿微信朋友圈图片切换展示特效</p>

代码结构

1. 引入CSS

<link rel="stylesheet" type="text/css" href="css/commes.css" />
<link rel="stylesheet" href="css/photoswipe.css">
<link rel="stylesheet" href="css/default-skin/default-skin.css">

2. 引入JS

<script src="js/photoswipe.min.js"></script>
<script src="js/photoswipe-ui-default.min.js"></script>

3. HTML代码

	<div class="container">
    	<!--用户头像-->
		<div class="header">
			<div><img src="images/s1_m.jpg" /></div>
		</div>
		<div class="right_con">
			<div class="demo">
            	<!--用户名and发布时间-->
            	<div class="use">
                	<div class="usename"><span>徐静蕾</span><em class="pub-time">刚刚</em></div>
                </div>
                <!--分享的内容-->
                <p class="fx_content">tank</p>
                <!--分享的图片-->
                <div class="my-gallery">
                    <figure>
                        <a href="images/s1.jpg" data-size="800x1142">
                            <img src="images/s1_m.jpg" />
                        </a>
                    </figure>
                    <figure>
                        <a href="images/s2.jpg" data-size="800x1142">
                            <img src="images/s2_m.jpg" />
                        </a>
                    </figure>
                    <figure>
                        <a href="images/s3.jpg" data-size="800x1142">
                            <img src="images/s3_m.jpg" />
                        </a>
                    </figure>
                    <figure>
                        <a href="images/s4.jpg" data-size="800x1142">
                            <img src="images/s4_m.jpg" />
                        </a>
                    </figure>
                    <figure>
                        <a href="images/s5.jpg" data-size="800x1142">
                            <img src="images/s5_m.jpg" />
                        </a>
                    </figure>
                    <figure>
                        <a href="images/s3.jpg" data-size="800x1142">
                            <img src="images/s3_m.jpg" />
                        </a>
                    </figure>
                    <figure>
                        <a href="images/s4.jpg" data-size="800x1142">
                            <img src="images/s4_m.jpg" />
                        </a>
                    </figure>
                    <figure>
                        <a href="images/s5.jpg" data-size="800x1142">
                            <img src="images/s5_m.jpg" />
                        </a>
                    </figure>
                </div>
                <!--显示的位置-->
                <div class="fx_address">南京市建邺区</div>
            </div>
		</div>
	</div>
    <div class="container">
    	<!--用户头像-->
		<div class="header">
			<div><img src="images/s1_m.jpg" /></div>
		</div>
		<div class="right_con">
			<div class="demo">
            	<!--用户名and发布时间-->
            	<div class="use">
                	<div class="usename"><span>徐静蕾</span><em class="pub-time">12:32</em></div>
                </div>
                <!--分享的内容-->
                <p class="fx_content">你不知道的晨跑,好消息,合作谈妥了!!!</p>
                <!--分享的图片-->
                <div class="my-gallery">
                    <figure>
                        <a href="images/s1.jpg" data-size="800x1142">
                            <img src="images/s1_m.jpg" alt="Image description" />
                        </a>
                    </figure>
                </div>
                <!--显示的位置-->
                <div class="fx_address">南京市建邺区</div>
            </div>
		</div>
	</div>
    <div class="container">
    	<!--用户头像-->
		<div class="header">
			<div><img src="images/s1_m.jpg" /></div>
		</div>
		<div class="right_con">
			<div class="demo">
            	<!--用户名and发布时间-->
            	<div class="use">
                	<div class="usename"><span>徐静蕾</span><em class="pub-time">10:59</em></div>
                </div>
                <!--分享的内容-->
                <p class="fx_content">你不知道的晨跑,好消息,合作谈妥了!!!</p>
                <!--分享的图片-->
                <div class="my-gallery">
                    <figure>
                        <a href="images/s1.jpg" data-size="800x1142">
                            <img src="images/s1_m.jpg" alt="Image description" />
                        </a>
                    </figure>
                    <figure>
                        <a href="images/s2.jpg" data-size="800x1142">
                            <img src="images/s2_m.jpg" alt="Image description" />
                        </a>
                    </figure>
                </div>
                <!--显示的位置-->
                <div class="fx_address"><a href="http://www.51qianduan.com/" target="_blank">51前端</a></div>
            </div>
		</div>
	</div>
<!--以下内容不要管-->
<div class="pswp" tabindex="-1" role="dialog" aria-hidden="true">
	<div class="pswp__bg"></div>
	<div class="pswp__scroll-wrap">
		<div class="pswp__container">
			<div class="pswp__item"></div>
			<div class="pswp__item"></div>
			<div class="pswp__item"></div>
		</div>
		<div class="pswp__ui pswp__ui--hidden">
			<div class="pswp__top-bar">
				<div class="pswp__counter"></div>
				<button class="pswp__button pswp__button--close" title="Close (Esc)"></button>
				<div class="pswp__preloader">
					<div class="pswp__preloader__icn">
						<div class="pswp__preloader__cut">
   							<div class="pswp__preloader__donut"></div>
                        </div>
                    </div>
                </div>
             </div>
             <div class="pswp__share-modal pswp__share-modal--hidden pswp__single-tap">
             	<div class="pswp__share-tooltip"></div> 
           	 </div>
             <button class="pswp__button pswp__button--arrow--left" title="Previous (arrow left)"></button>
             <button class="pswp__button pswp__button--arrow--right" title="Next (arrow right)"></button>
             <div class="pswp__caption">
             	<div class="pswp__caption__center"></div>
			 </div>
		</div>
	</div>
</div>
        <script src="js/photoswipe.min.js"></script> 
        <script src="js/photoswipe-ui-default.min.js"></script> 
        <script type="text/javascript">
            var initPhotoSwipeFromDOM = function(gallerySelector) {
                // parse slide data (url, title, size ...) from DOM elements 
                // (children of gallerySelector)
                var parseThumbnailElements = function(el) {
                    var thumbElements = el.childNodes,
                            numNodes = thumbElements.length,
                            items = [],
                            figureEl,
                            linkEl,
                            size,
                            item;
                    for (var i = 0; i < numNodes; i++) {
                        figureEl = thumbElements[i]; // <figure> element
                        // include only element nodes 
                        if (figureEl.nodeType !== 1) {
                            continue;
                        }
                        linkEl = figureEl.children[0]; // <a> element
                        size = linkEl.getAttribute('data-size').split('x');
                        // create slide object
                        item = {
                            src: linkEl.getAttribute('href'),
                            w: parseInt(size[0], 10),
                            h: parseInt(size[1], 10)
                        };
                        if (figureEl.children.length > 1) {
                            // <figcaption> content
                            item.title = figureEl.children[1].innerHTML;
                        }
                        if (linkEl.children.length > 0) {
                            // <img> thumbnail element, retrieving thumbnail url
                            item.msrc = linkEl.children[0].getAttribute('src');
                        }
                        item.el = figureEl; // save link to element for getThumbBoundsFn
                        items.push(item);
                    }
                    return items;
                };
                // find nearest parent element
                var closest = function closest(el, fn) {
                    return el && (fn(el) ? el : closest(el.parentNode, fn));
                };
                // triggers when user clicks on thumbnail
                var onThumbnailsClick = function(e) {
                    e = e || window.event;
                    e.preventDefault ? e.preventDefault() : e.returnValue = false;
                    var eTarget = e.target || e.srcElement;
                    // find root element of slide
                    var clickedListItem = closest(eTarget, function(el) {
                        return (el.tagName && el.tagName.toUpperCase() === 'FIGURE');
                    });
                    if (!clickedListItem) {
                        return;
                    }
                    // find index of clicked item by looping through all child nodes
                    // alternatively, you may define index via data- attribute
                    var clickedGallery = clickedListItem.parentNode,
                            childNodes = clickedListItem.parentNode.childNodes,
                            numChildNodes = childNodes.length,
                            nodeIndex = 0,
                            index;
                    for (var i = 0; i < numChildNodes; i++) {
                        if (childNodes[i].nodeType !== 1) {
                            continue;
                        }
                        if (childNodes[i] === clickedListItem) {
                            index = nodeIndex;
                            break;
                        }
                        nodeIndex++;
                    }
                    if (index >= 0) {
                        // open PhotoSwipe if valid index found
                        openPhotoSwipe(index, clickedGallery);
                    }
                    return false;
                };
                // parse picture index and gallery index from URL (#&pid=1&gid=2)
                var photoswipeParseHash = function() {
                    var hash = window.location.hash.substring(1),
                            params = {};
                    if (hash.length < 5) {
                        return params;
                    }
                    var vars = hash.split('&');
                    for (var i = 0; i < vars.length; i++) {
                        if (!vars[i]) {
                            continue;
                        }
                        var pair = vars[i].split('=');
                        if (pair.length < 2) {
                            continue;
                        }
                        params[pair[0]] = pair[1];
                    }
                    if (params.gid) {
                        params.gid = parseInt(params.gid, 10);
                    }
                    return params;
                };
                var openPhotoSwipe = function(index, galleryElement, disableAnimation, fromURL) {
                    var pswpElement = document.querySelectorAll('.pswp')[0],
                            gallery,
                            options,
                            items;
                    items = parseThumbnailElements(galleryElement);
                    // define options (if needed)
                    options = {
                        // define gallery index (for URL)
                        galleryUID: galleryElement.getAttribute('data-pswp-uid'),
                        getThumbBoundsFn: function(index) {
                            // See Options -> getThumbBoundsFn section of documentation for more info
                            var thumbnail = items[index].el.getElementsByTagName('img')[0], // find thumbnail
                                    pageYScroll = window.pageYOffset || document.documentElement.scrollTop,
                                    rect = thumbnail.getBoundingClientRect();
                            return {x: rect.left, y: rect.top + pageYScroll, w: rect.width};
                        }
                    };
                    // PhotoSwipe opened from URL
                    if (fromURL) {
                        if (options.galleryPIDs) {
                            // parse real index when custom PIDs are used 
                            // http://photoswipe.com/documentation/faq.html#custom-pid-in-url
                            for (var j = 0; j < items.length; j++) {
                                if (items[j].pid == index) {
                                    options.index = j;
                                    break;
                                }
                            }
                        } else {
                            // in URL indexes start from 1
                            options.index = parseInt(index, 10) - 1;
                        }
                    } else {
                        options.index = parseInt(index, 10);
                    }
                    // exit if index not found
                    if (isNaN(options.index)) {
                        return;
                    }
                    if (disableAnimation) {
                        options.showAnimationDuration = 0;
                    }
                    // Pass data to PhotoSwipe and initialize it
                    gallery = new PhotoSwipe(pswpElement, PhotoSwipeUI_Default, items, options);
                    gallery.init();
                };
                // loop through all gallery elements and bind events
                var galleryElements = document.querySelectorAll(gallerySelector);
                for (var i = 0, l = galleryElements.length; i < l; i++) {
                    galleryElements[i].setAttribute('data-pswp-uid', i + 1);
                    galleryElements[i].onclick = onThumbnailsClick;
                }
                // Parse URL and open gallery if it contains #&pid=3&gid=1
                var hashData = photoswipeParseHash();
                if (hashData.pid && hashData.gid) {
                    openPhotoSwipe(hashData.pid, galleryElements[ hashData.gid - 1 ], true, true);
                }
            };
        // execute above function
            initPhotoSwipeFromDOM('.my-gallery');
        </script>



用户评论
大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册


热门标签: 图片叠加 图片层叠 图片全屏 图片淡出淡进 图片淡出 图片淡进 图片延迟加载 图片延迟 图片加载 图片翻转 图片旋转 图片放大镜 头像上传 图片上传 图片拖动 图片拖拽 二维码 图片放大缩小 图片缩放 图片大小 图片放大 图片缩小 图片变大 图片变小 滚动切换 滚动条切换 带缩略图的幻灯片 h5图片动画 h5图标动画 html5图片动画 html5图标动画 地图 中国地图 世界地图 滑动选项卡 滑动切换 图片广告 图片收缩展开 图片收缩 图片展开 纯图片轮播 图片轮播 图片切换 图片选项卡 图标选项卡 旋转木马 图片旋转木马 文字旋转木马 旋转木马插件 图片滑动 图片滑块 图片滚动 图片滚动条 弹出层拖动 图标导航 图标菜单 自动滚动图片轮播 选项卡切换 选项卡 切换 tab切换 页面切换 选项卡插件 切换插件 背景切换 大图切换 滑动手风琴 手风琴 水平手风琴 垂直手风琴 图片手风琴 文字手风琴 手风琴插件 窗口 弹出 弹窗 弹出层 提示框 对话框 遮罩 遮罩层 弹窗插件 切换按钮 图表 表单 表单美化 表单插件 表单美化插件 图片 图片插件 头像截图 图片切换 图片选项卡 图标选项卡 lightbox 图片切换 切换图片 按钮控制

×
×

注册

官方QQ群

扫描上面二维码加微信群

官方QQ群

jQuery/js讨论群
群号:642649996
Css3+Html5讨论群
群号:322131262

加群请备注:从官网了解到