素材牛VIP会员

jQuery响应式图片弹出层和对话框插件MagnificPopup

 所属分类:网页特效-图片特效,对话框/灯箱/提示,悬浮层/弹出层

 浏览:2402次  评论:0次  更新时间:2016-10-06
牛币素材VIP可免积分下载
jQuery响应式图片弹出层和对话框插件MagnificPopup兼容IE8
积分说明:注册即送10牛币,每日签到可获得5牛币,成为VIP会员可永久免牛币下载!   充值积分   充值会员   更多说明»
素材描述:Magnific Popup 是一个响应式弹出层和对话框组件,专注于性能,为用户在各种平台下提供良好的体验。

详细介绍

使用方法:

引用CSS样式文件、jQuery库文件、插件JS文件

<!-- Magnific Popup core CSS file -->  
<link rel="stylesheet" href="css/magnific-popup.css">   
  
<!-- jQuery 1.7.2+ or Zepto.js 1.0+ -->  
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script> 
  
<!-- Magnific Popup core JS file -->  
<script src="js/jquery.magnific-popup.min.js"></script>   

插件初始化、参数配置

$(document).ready(function() {
	$('.gallery').each(function() { // the containers for all your galleries
		$(this).magnificPopup({
			delegate: 'a', // the selector for gallery item
			type: 'image',
			gallery: {
			  enabled:true
			}
		});
	});
});

有三种方法可以调用一个popup

1、通过一个HTML元素

<a class="test-popup-link" href="path-to-image.jpg">Open popup</a>  
$('.test-popup-link').magnificPopup({   
  type: 'image'  
    // other options  
});

2、通过一组有共同父元素的子元素

和之前的一样,不同的是创建一个弹出列表。注意,此方法不支持gallery(画廊)模式,它只不过减少了单击事件处理函数的数量――每个元素以独立的窗口弹出。如果你要使用gallery模式,添加gallery:{enabled:true}选项。

<div class="parent-container">  
  <a href="path-to-image-1.jpg">Open popup 1</a>  
  <a href="path-to-image-2.jpg">Open popup 2</a>  
  <a href="path-to-image-3.jpg">Open popup 3</a>  
</div>  
$('.parent-container').magnificPopup({  
  delegate: 'a', // child items selector, by clicking on it popup will open  
  type: 'image'  
  // other options  
});

3、通过“items”选项

items选项为弹出项定义了一组数据,并且让Magnific Popup忽略目标DOM元素的所有属性值。items的值可以是单个对象或一个对象数组。

// Example with single object  
$('#some-button').magnificPopup({  
    items: {  
      src: 'path-to-image-1.jpg'  
    },  
    type: 'image' // this is default type  
});  
  
// Example with multiple objects  
$('#some-button').magnificPopup({  
    items: [  
      {  
        src: 'path-to-image-1.jpg'  
      },  
      {  
        src: 'http://vimeo.com/123123',  
        type: 'iframe' // this overrides default type  
      },  
      {  
        src: $('<div>Dynamically created element</div>'), // Dynamically created element  
        type: 'inline'  
      },  
      {  
        src: '<div>HTML string</div>',  
        type: 'inline'  
      },  
      {  
        src: '#my-popup', // CSS selector of an element on page that should be used as a popup  
        type: 'inline'  
      }  
    ],  
    gallery: {  
      enabled: true  
    },  
    type: 'image' // this is default type  
});

Content Types

Magnific Popup 一般支持4种类型:image、iframe、inline和ajax。由于并不存在基于URL的自动探测机制,因此你必须手工指定它。

有两种方法可以定义content type:

1、使用type选项,例如:

$('.image-link').magnificPopup({type:'image'})

2、使用 mfp-TYPE CSS 类,例如:

<a class="mfp-image image-link">Open image</a>, $('.image-link').magnificPopup()

其中,第二种方法会覆盖第一种方法,因此你可以在一次调用定义多种类型的content type。

inline是默认的content type(从v0.8.4以来)。

有几种方法可以定义弹出窗口的源(例如,一张图片、一个HTML文档,一个视频页):

方法一:使用 href 属性:

<a href="image-for-popup.jpg">Open image</a>

方法二:使用data-mfp-src属性(覆盖方法一):

<a href="some-image.jpg" data-mfp-src="image-for-popup.jpg">Open image</a>

方法三:使用 items 选项:

<pre name="code" class="javascript">$.magnificPopup.open({  
  items: {  
    src: 'some-image.jpg'  
  },  
  type: 'image'  
});


相关素材 - 图片特效,对话框/灯箱/提示,悬浮层/弹出层

讨论这个素材(0)回答他人问题或分享使用心得会奖励牛币

〒_〒 居然一个评论都没有……

 文明上网,理性发言!   😉 阿里云幸运券,戳我领取
我的牛币余额:0
所需牛币:1 开始下载

牛币获取:签到、评论、充值    » 在线充值(10牛币=1元)