首页 前端知识 JS特效第117弹:jQuery图片放大镜插件鼠标悬停图片缩放代码

JS特效第117弹:jQuery图片放大镜插件鼠标悬停图片缩放代码

2024-06-06 00:06:18 前端知识 前端哥 280 114 我要收藏

        jQuery图片放大镜插件支持整张图片和局部图片放大查看,通过鼠标滚动控制图片缩放效果代码(不兼容IE6,7,8) ,先来看看效果:

        一部分关键的代码如下:

<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
<meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1">
<title>jQuery支持局部缩放图片放大镜插件</title>

<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="src/css/mag.css" />
<link rel="stylesheet" href="src/theme/default.css" />
<link rel="stylesheet" href="css/index.css" />

<style type="text/css">
.controls-btns button{
	color: #333;
}
.mt50{margin-top: 50px;}
</style>

</head>
<body>

<div class="container mt50">
  <main>
	<div class="row mag-eg-row">
	  <div class="col col-md-6">
		<div class="mag-eg-el-wrap img-thumbnail">
		  <div class="proportion">
			<div mag-thumb="inner" class="mag-eg-el">
			  <img src="img/alley/500x300.jpg" />
			</div>
			<div mag-zoom="inner" class="mag-eg-el">
			  <img src="img/alley/1000x600.jpg" />
			</div>
			<div class="filler"></div>
		  </div>
		</div>
	  </div>
	  <div class="col col-md-6">
		<div class="mag-eg-doc">
		  <h3>Inner</h3>
		  <pre><code class="lang-html"><!--
-->&lt;div mag-thumb=&quot;inner&quot;&gt;
&lt;img src=&quot;img/alley/500x300.jpg&quot; /&gt;
&lt;/div&gt;
&lt;div mag-zoom=&quot;inner&quot;&gt;
&lt;img src=&quot;img/alley/1000x600.jpg&quot; /&gt;
&lt;/div&gt;<!--
		  --></code></pre>
		  <pre><code class="lang-js"><!--
-->$host = $('[mag-thumb=&quot;inner&quot;]');
$host.mag();<!--
		  --></code></pre>
		  <p>使用鼠标滚轮可以对内部图片进行缩放。</p>
		</div>
	  </div>
	</div>

	<div class="row mag-eg-row">
	  <div class="col col-md-6">
		<div class="mag-eg-el-wrap">
		  <div class="img-thumbnail">
			<div mag-thumb="inner-inline" mag-flow="inline" class="mag-eg-el">
			  <img src="img/alley/500x300.jpg" style="width: 400px; max-width: 100%; height: auto" />
			</div>
			<div mag-zoom="inner-inline" class="mag-eg-el">
			  <img src="img/alley/1000x600.jpg" />
			</div>
		  </div>
		</div>
	  </div>
	  <div class="col col-md-6">
		<div class="mag-eg-doc">
		  <h3>Inner Inline</h3>
		  <pre><code class="lang-html"><!--
-->&lt;div mag-thumb=&quot;inner-inline&quot; mag-flow=&quot;inline&quot;&gt;
&lt;img src=&quot;img/alley/500x300.jpg&quot; style=&quot;width: 400px; max-width:100%;&quot; /&gt;
&lt;/div&gt;
&lt;div mag-zoom=&quot;inner-inline&quot;&gt;
&lt;img src=&quot;img/alley/1000x600.jpg&quot; /&gt;
&lt;/div&gt;<!--
		  --></code></pre>
		  <pre><code class="lang-js"><!--
-->$host = $('[mag-thumb=&quot;inner-inline&quot;]');
$host.mag();<!--
		  --></code></pre>

		</div>
	  </div>
	</div>

	<div class="row mag-eg-row">
	  <div class="col col-md-6">
		<div class="mag-eg-el-wrap img-thumbnail">
		  <div class="proportion">
			<div mag-thumb="outer" class="mag-eg-el">
			  <img src="img/rieti/500x334.jpg" />
			</div>
			<div class="filler"></div>
		  </div>
		</div>
		<div class="mag-eg-el-wrap img-thumbnail" style="height:auto;width:auto">
		  <div style="height: 300px; width: 300px">
			<div mag-zoom="outer" class="mag-eg-el" style="float: right;position:relative;overflow:hidden;">
			  <img src="img/rieti/full.jpg" />
			</div>
		  </div>
		</div>
	  </div>
	  <div class="col col-md-6">
		<div class="mag-eg-doc">
		  <h3>Outer</h3>
		  <pre><code class="lang-html"><!--
-->&lt;div mag-thumb=&quot;outer&quot;&gt;
&lt;img src=&quot;img/alley/500x300.jpg&quot; /&gt;
&lt;/div&gt;
&lt;div style=&quot;width: 300px; height: 300px;&quot;&gt;
&lt;div mag-zoom=&quot;outer&quot;&gt;
&lt;img src=&quot;img/alley/1000x600.jpg&quot; /&gt;
&lt;/div&gt;
&lt;/div&gt;<!--
		  --></code></pre>
		  <pre><code class="lang-js"><!--
-->$host = $('[mag-thumb=&quot;outer&quot;]');
$host.mag({
mode: 'outer',
ratio: 1 / 1.6
});
		  </code></pre>
		  <p>使用鼠标滚轮可以对外部图片进行缩放。</p>
		</div>
	  </div>
	</div>



	<div class="row mag-eg-row">
	  <div class="col col-md-6">
		<div class="mag-eg-el-wrap img-thumbnail">
		  <div class="proportion">
			<div mag-thumb="outer-drag" class="mag-eg-el">
			  <img src="img/rieti/500x334.jpg" />
			</div>
			<div class="filler"></div>
		  </div>
		</div>
		<div class="mag-eg-el-wrap img-thumbnail">
		  <div class="proportion">
			<div mag-zoom="outer-drag" class="mag-eg-el" style="float: right;">
			  <img src="img/rieti/full.jpg" />
			</div>
			<div class="filler"></div>
		  </div>
		</div>
	  </div>
	  <div class="col col-md-6">
		<div class="mag-eg-doc">
		  <h3>Outer Drag</h3>
		  <pre><code class="lang-html"><!--
-->&lt;div mag-thumb=&quot;outer-drag&quot;&gt;
&lt;img src=&quot;img/alley/500x300.jpg&quot; /&gt;
&lt;/div&gt;
&lt;div mag-zoom=&quot;outer-drag&quot;&gt;
&lt;img src=&quot;img/alley/1000x600.jpg&quot; /&gt;
&lt;/div&gt;
<!--
		  --></code></pre>
		  <pre><code class="lang-js"><!--
-->$host = $('[mag-thumb=&quot;outer-drag&quot;]');
$host.mag({
mode: 'outer',
position: 'drag',
toggle: false
});<!--
		  --></code></pre>
		  <p>使用鼠标滚轮可以对外部图片进行缩放。</p>
		</div>
	  </div>
	</div>

	<div class="row mag-eg-row">
	  <div class="col col-md-6">
		<div class="mag-eg-el-wrap img-thumbnail">
		  <div class="proportion">
			<div mag-thumb="drag" class="mag-eg-el">
			  <img src="img/rieti/500x334.jpg" />
			</div>
			<div mag-zoom="drag" class="mag-eg-el">
			  <img src="img/rieti/full.jpg" />
			</div>
			<div class="filler"></div>
		  </div>
		</div>
	  </div>
	  <div class="col col-md-6">
		<div class="mag-eg-doc">
		  <h3>Drag</h3>
		  <pre><code class="lang-html"><!--
-->&lt;div mag-thumb=&quot;drag&quot;&gt;
&lt;img src=&quot;img/alley/500x300.jpg&quot; /&gt;
&lt;/div&gt;
&lt;div mag-zoom=&quot;drag&quot;&gt;
&lt;img src=&quot;img/alley/1000x600.jpg&quot; /&gt;
&lt;/div&gt;<!--
		  --></code></pre>
		  <pre><code class="lang-js"><!--
-->$host = $('[mag-thumb=&quot;drag&quot;]');
$host.mag({
position: 'drag',
toggle: false
});<!--
		  --></code></pre>
		  <p>使用鼠标滚轮可以对图片进行缩放。</p>
		</div>
	  </div>
	</div>


	<div class="row mag-eg-row" id="controls">
	  <div class="col col-md-6">
		<div class="mag-eg-el-wrap img-thumbnail">
		  <div class="proportion">
			<div mag-thumb="controls" class="mag-eg-el">
			  <img src="img/rieti/500x334.jpg" />
			</div>
			<div mag-zoom="controls" class="mag-eg-el">
			  <img src="img/rieti/full.jpg" />
			</div>
			<div class="filler"></div>
		  </div>
		</div>
		<div mag-ctrl="controls" class="controls-btns">
		  <button class="mag-eg-ctrl-zoom-out" mag-ctrl-zoom-by="-0.5">-</button>
		  <button class="mag-eg-ctrl-zoom-in" mag-ctrl-zoom-by="0.5">+</button>
		  <button class="mag-eg-ctrl-move-up" mag-ctrl-move-by-y="-0.5">^</button>
		  <button class="mag-eg-ctrl-move-down" mag-ctrl-move-by-y="0.5">v</button>
		  <button class="mag-eg-ctrl-move-left" mag-ctrl-move-by-x="-0.5">&lt;</button>
		  <button class="mag-eg-ctrl-move-right" mag-ctrl-move-by-x="0.5">&gt;</button>
		  <button class="mag-eg-ctrl-fullscreen" mag-ctrl-fullscreen>[ ]</button>
		  <button class="mag-eg-ctrl-destroy" mag-ctrl-destroy>destroy</button>
		</div>
	  </div>
	  <div class="col col-md-6">
		<div class="mag-eg-doc">
		  <h3><a href="#controls">Controls</a></h3>
		  <pre><code class="lang-html"><!--
-->&lt;script src="src/js/mag-control.js"&gt;&lt;/script&gt;

&lt;div mag-thumb=&quot;controls&quot;&gt;
&lt;img src=&quot;img/alley/500x300.jpg&quot; /&gt;
&lt;/div&gt;
&lt;div mag-zoom=&quot;controls&quot;&gt;
&lt;img src=&quot;img/alley/1000x600.jpg&quot; /&gt;
&lt;/div&gt;

&lt;div mag-ctrl=&quot;controls&quot;&gt;
&lt;button mag-ctrl-zoom-by=&quot;-0.5&quot;&gt;-&lt;/button&gt;
&lt;button mag-ctrl-zoom-by=&quot;0.5&quot;&gt;+&lt;/button&gt;
&lt;button mag-ctrl-move-by-y=&quot;-0.5&quot;&gt;^&lt;/button&gt;
&lt;button mag-ctrl-move-by-y=&quot;0.5&quot;&gt;v&lt;/button&gt;
&lt;button mag-ctrl-move-by-x=&quot;-0.5&quot;&gt;&lt;&lt;/button&gt;
&lt;button mag-ctrl-move-by-x=&quot;0.5&quot;&gt;&gt;&lt;/button&gt;
&lt;button mag-ctrl-fullscreen&gt;[ ]&lt;/button&gt;
&lt;button mag-ctrl-destroy&gt;destroy&lt;/button&gt;
&lt;/div&gt;<!--
		  --></code></pre>
		  <pre><code class="lang-js"><!--
-->$host = $('[mag-thumb=&quot;controls&quot;]');
$host.mag(
toggle: false,
position: false
);

$controls = $('[mag-ctrl="controls"]');
$controls.magCtrl({
mag: $host
});<!--
		--></code></pre>
		</div>
	  </div>
	</div>


  </main>
</div>

<script src="js/jquery.min.js"></script>
<script src="js/jquery.bridget.js"></script>
<script src="js/jquery.mousewheel.min.js"></script>
<script src="js/jquery.event.drag.js"></script>
<script src="js/screenfull.js"></script>
<script src="js/hammer.min.js"></script>
<script src="js/PreventGhostClick.js"></script>
<script src="src/js/mag-analytics.js"></script>
<script src="src/js/mag.js"></script>
<script src="src/js/mag-jquery.js"></script>
<script src="src/js/mag-control.js"></script>
<script src="js/index.js"></script>


</body>
</html>

        全部代码:jQuery图片放大镜插件鼠标悬停图片缩放代码

转载请注明出处或者链接地址:https://www.qianduange.cn//article/10920.html
标签
评论
发布的文章

JQuery中的load()、$

2024-05-10 08:05:15

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!