jquery實現(xiàn)移動端點擊圖片查看大圖特效
本文的需求很簡單:點擊圖片查看大圖,再點大圖隱藏。多用于移動端,因為移動端屏幕小,可能需要查看大圖。
具體實現(xiàn)代碼
<!DOCTYPE html>
<html>
<meta charset="utf-8"/>
<head runat="server">
<title>JQuery點擊圖片查看大圖by starof</title>
<style type="text/css">
.exampleImg { height:100px; cursor:pointer;}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
//alert($);
// (function (window, undefined) {
// var MyJQuery = function () {
// window.MyjQuery = window.$ = jQuery; window.$ = MyJQuery;
// };
// })(window);
// alert($);
$.fn.ImgZoomIn = function () {
bgstr = '<div id="ImgZoomInBG" style=" background:#000000; filter:Alpha(Opacity=70); opacity:0.7; position:fixed; left:0; top:0; z-index:10000; width:100%; height:100%; display:none;"><iframe src="about:blank" frameborder="5px" scrolling="yes" style="width:100%; height:100%;"></iframe></div>';
//alert($(this).attr('src'));
imgstr = '<img id="ImgZoomInImage" src="' + $(this).attr('src')+'" onclick=$(\'#ImgZoomInImage\').hide();$(\'#ImgZoomInBG\').hide(); style="cursor:pointer; display:none; position:absolute; z-index:10001;" />';
if ($('#ImgZoomInBG').length < 1) {
$('body').append(bgstr);
}
if ($('#ImgZoomInImage').length < 1) {
$('body').append(imgstr);
}
else {
$('#ImgZoomInImage').attr('src', $(this).attr('src'));
}
//alert($(window).scrollLeft());
//alert( $(window).scrollTop());
$('#ImgZoomInImage').css('left', $(window).scrollLeft() + ($(window).width() - $('#ImgZoomInImage').width()) / 2);
$('#ImgZoomInImage').css('top', $(window).scrollTop() + ($(window).height() - $('#ImgZoomInImage').height()) / 2);
$('#ImgZoomInBG').show();
$('#ImgZoomInImage').show();
};
$(document).ready(function () {
$("#imgTest").bind("click", function () {
$(this).ImgZoomIn();
});
});
</script>
</head>
<body>
<div>
<!--第一種寫法-->
<img class="exampleImg" src="images/03.jpg" id="imgTest"/>
<!--第二種寫法-->
<img class="exampleImg" src="images/p1_nav2.png" onClick="$(this).ImgZoomIn();"/>
</div>
</body>
</html>

jquery實現(xiàn)移動端點擊圖片查看大圖特效需要用到的技巧
需要點擊圖片中1、2、3、4四張小圖分別查看大圖,而下面左右按鈕切換時是需要同時切換4張小圖。

因為移動端無法添加熱點,最終一個解決方法是使用四個a標簽定位到左上角,右上角,左下角,右下角四個區(qū)域。
<dl> <dd style="display:block;"> <img src="images/four-duche.jpg" onClick="$(this).ImgZoomIn();"> <a href="javascript:;" src="images/11.jpg" class="topleft" onClick="$(this).ImgZoomIn();"></a> <a href="javascript:;" src="images/12.jpg" class="topright" onClick="$(this).ImgZoomIn();"></a> <a href="javascript:;" src="images/13.jpg" class="bottomleft" onClick="$(this).ImgZoomIn();"></a> <a href="javascript:;" src="images/14.jpg" class="bottomright" onClick="$(this).ImgZoomIn();"></a> </dd> ... </dl>
css
.topleft,.topright,.bottomleft,.bottomright{
width:50%;
height:50%;
position:absolute;
}
.topleft{
/*background-color:red;*/
top:0;
left:0;
}
.topright{
/*background-color:green;*/
top:0;
right:0;
}
.bottomleft{
/*background-color:blue;*/
bottom:0;
left:0;
}
.bottomright{
/*background-color:yellow;*/
bottom:0;
right:0;
}
以上就是移動端點擊圖片查看大圖的實現(xiàn)過程,希望對大家的學習有所幫助。
- jQuery實現(xiàn)等比例縮放大圖片讓大圖片自適應頁面布局
- 基于jquery的防止大圖片撐破頁面的實現(xiàn)代碼(立即縮放)
- jQuery+css實現(xiàn)的點擊圖片放大縮小預覽功能示例【圖片預覽 查看大圖】
- jQuery實現(xiàn)鼠標滑過商品小圖片上顯示對應大圖片功能【測試可用】
- jQuery實現(xiàn)鼠標滑過預覽圖片大圖效果的方法
- jQuery實現(xiàn)大圖輪播
- jQuery實現(xiàn)的小圖列表,大圖展示效果幻燈片示例
- jquery插件jquery.LightBox.js實現(xiàn)點擊放大圖片并左右點擊切換效果(附demo源碼下載)
- jQuery實現(xiàn)點擊小圖片淡入淡出顯示大圖片特效
- jQuery實現(xiàn)點擊查看大圖并以彈框的形式居中
- 基于jQuery插件實現(xiàn)點擊小圖顯示大圖效果
- jQuery實現(xiàn)點擊小圖顯示大圖代碼分享
- jquery 圖片點擊放大預覽功能詳解
相關文章
jquery實現(xiàn)的帶縮略圖的焦點圖片切換(自動播放/響應鼠標動作)
帶縮略圖的焦點圖片切換在實際應用中很廣泛的,鼠標滑上焦點圖時停止自動播放,滑出時開始自動播放及鼠標滑上后顯示按鈕、顯示大圖等等,感興趣的朋友可以了解下2013-01-01
jQuery-serialize()輸出序列化form表單值的方法
jQuery-serialize()輸出序列化表單值在工作中很常見也很實用,于是本人搜集整理了一些,需要了解的朋友可以詳細參考下2012-12-12
jQuery動態(tài)添加元素無法觸發(fā)綁定事件的解決方法分析
這篇文章主要介紹了jQuery動態(tài)添加元素無法觸發(fā)綁定事件的解決方法,結合實例形式分析了動態(tài)添加元素無法綁定事件的原因與相關解決方法,需要的朋友可以參考下2018-01-01
jQuery powerFloat萬能浮動層下拉層插件使用介紹
支持hover, click, focus以及無事件觸發(fā);支持多達12種位置的定位,出界自動調整;支持頁面元素加載,Ajax加載,下拉列表,提示層效果,tip類效果等;可自定義裝載容器;內(nèi)置UI不錯的裝載容器;支持鼠標跟隨等。2010-12-12
jQuery源碼分析-03構造jQuery對象-源碼結構和核心函數(shù)
jQuery源碼分析-03構造jQuery對象-源碼結構和核心函數(shù),需要的朋友可以參考下。2011-11-11

