成人精品一区二区三区中文字幕-成人精品一区二区三区-成人精品一级毛片-成人精品亚洲-日本在线视频一区二区-日本在线视频免费

導航首頁 ? 技術教程 ? jquery實現移動端點擊圖片查看大圖特效
全站頭部文字 我要出現在這里
jquery實現移動端點擊圖片查看大圖特效 642 2024-03-20   

本文的需求很簡單:點擊圖片查看大圖,再點大圖隱藏。多用于移動端,因為移動端屏幕小,可能需要查看大圖。

具體實現代碼

<!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="http://www.gimoo.net/t/1904/5cb947c2edb85.html' + $(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="http://www.gimoo.net/t/1904/images/03.jpg" id="imgTest"/>
<第二種寫法-->
<img class="exampleImg" src="http://www.gimoo.net/t/1904/images/p1_nav2.png" onClick="$(this).ImgZoomIn();"/>
</div>
</body>
</html>

查看圖片

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


查看圖片

因為移動端無法添加熱點,最終一個解決方法是使用四個a標簽定位到左上角,右上角,左下角,右下角四個區域。

<dl>
  <dd style="display:block;">
    <img src="http://www.gimoo.net/t/1904/images/four-duche.jpg" onClick="$(this).ImgZoomIn();">
    <a href="javascript:;" src="http://www.gimoo.net/t/1904/images/11.jpg" class="topleft" onClick="$(this).ImgZoomIn();"></a>
    <a href="javascript:;" src="http://www.gimoo.net/t/1904/images/12.jpg" class="topright" onClick="$(this).ImgZoomIn();"></a>
    <a href="javascript:;" src="http://www.gimoo.net/t/1904/images/13.jpg" class="bottomleft" onClick="$(this).ImgZoomIn();"></a>
    <a href="javascript:;" src="http://www.gimoo.net/t/1904/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;
}

以上就是移動端點擊圖片查看大圖的實現過程,希望對大家的學習有所幫助。



主站蜘蛛池模板: 玫瑰情人| 一块奶酪预习| 好医生5| 植田圭辅| 拔萝卜无删减| 生死瞬间演员表| 海南岛全景图| 金马电影网| 电视剧《流金岁月》演员表| 五年级语文下册| 水牛城66| 3s游戏交易平台| 我的女老师| 淡蓝色的雨简谱| 少女模特电影| 学籍证明| 叶子楣哪部三级露了| 杨紫和肖战演的电视剧是什么| 吉泽明步电影| 小红书如何开通店铺| 国产精品久久久久精品三级ⅰ| 秦时明月动画片| 笼中之怒| 《身边有特点的人》作文| 控制点电影| 故乡之恋简谱| coco电影| 国产艳遇久久久久久久精品电影| 隐形人4| 355 电影| 林赛斯特林| 玛姬·格蕾斯| 布谷鸟 电影| 抖音下载| cgtn news| 风月奇谭电影| midjourney中文版| 三星报喜| 必修一英语电子课本外研版| 熊出没免费电影| 首映式|

!!!站長長期在線接!!!

網站、小程序:定制開發/二次開發/仿制開發等

各種疑難雜癥解決/定制接口/定制采集等

站長微信:lxwl520520

站長QQ:1737366103