jQuery實現(xiàn)查看圖片功能
更新時間:2020年12月01日 09:22:56 作者:從入門to入萬
這篇文章主要為大家詳細介紹了jQuery實現(xiàn)查看圖片,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
本文實例為大家分享了jQuery實現(xiàn)查看圖片的具體代碼,供大家參考,具體內容如下
HTML
<!-- 放縮略圖的div --> <div class="sl"> <img src="images/1.jpg" /> <img src="images/2.jpg" /> <img src="images/3.jpg" /> </div> <!-- 實現(xiàn)關燈的div --> <div class="gd"></div> <div class="yt"> <!-- 左翻按鈕 --> <div class="left"> <img src="images/left.png" alt="" width="100"> </div> <div class="tp"> <!-- 展示原圖 --> <img src="images/1.jpg" class="show" /> <!--放開始和結束圖片的盒子 --> <div class="ss" style="display: none;"> <img src="images/start.png" alt="" width="50" class="start"> </div> </div> <!-- 右翻按鈕 --> <div class="right"> <img src="images/right.png" alt="" width="100"> </div> </div>
CSS
html,body{ padding: 0; margin: 0; } .sl img { width: 300px; } .gd { background-color: rgba(0, 0, 0, 0.7); position: absolute; z-index: 900; display: none; top: 0; left: 0; } .sl { position: absolute; z-index: 888; display: flex; flex-wrap: wrap; justify-content: center; } .sl>img { width: 25%; } .yt { z-index: 990; position: absolute; display: none; left: 500px; top: 200px; } .tp { margin: 0 20px; } .yt>div { display: inline-block; } .left, .right { position: relative; top: -110px; cursor: pointer; } .ss { position: relative; width: 50px; height: 50px; left: 270px; } .start { z-index: 990; position: absolute; }
JS
var max = $(".sl img").length; $(function (e) { var width = $(window).width(); var height = $(window).height(); $(".gd").css({ "height": height, "width": width }); //左翻按鈕動畫 $(".left").hover( function () { $(this).animate({ "left": "-10" }); }, function () { $(this).animate({ "left": "0" }); } ); //右翻按鈕動畫 $(".right").hover( function () { $(this).animate({ "right": "-10" }); }, function () { $(this).animate({ "right": "0" }); } ); //被點擊的縮略圖 $(".sl>img").click(function (e) { $(".gd").show(500); $(".yt").fadeIn(800); var index = $(this).index(); //當前被點擊圖片的索引 $(".tp>img").attr("src", "images/" + (index + 1) + ".jpg"); //左翻 $(".left").click(function (e) { if (index - 1 < 0) { index = max - 1; } else { index = index - 1; } $(".tp>img").attr("src", "images/" + (index + 1) + ".jpg"); }); //右翻 $(".right").click(function (e) { if (index == max - 1) { index = 0; } else { index = index + 1; } $(".tp>img").attr("src", "images/" + (index + 1) + ".jpg"); }); //隱藏和顯示播放按鈕 $(".tp").hover( function () { $(".ss").fadeIn(500); $(this).animate({ "opacity": "0.7" }, 700); }, function () { $(".ss").fadeOut(500); $(this).animate({ "opacity": "1" }, 700); } ); //點擊開始播放 再次點擊結束播放 let flag = true; $(".start").click(function () { if (flag == true) { time = setInterval(function () { if (index == max - 1) { index = 0; } else { index = index + 1; } $(".tp>img").attr("src", "images/" + (index + 1) + ".jpg"); }, 2000); flag = false; $(".start").attr("src", "images/stop.png"); } else { clearInterval(time); flag = true; $(".start").attr("src", "images/start.png"); } }); let h = $(".tp>img").height(); $(".ss").css({ "top": -h / 2 - 25 }); //隱藏關燈效果 $(".gd").click(function () { $(".gd").hide(800); $(".yt").fadeOut(500); }); }); });
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
jQuery插件FusionCharts實現(xiàn)的MSBar2D圖效果示例【附demo源碼】
這篇文章主要介紹了jQuery插件FusionCharts實現(xiàn)的MSBar2D圖效果,結合實例形式分析了jQuery使用FusionCharts插件結合xml數(shù)據(jù)載入實現(xiàn)繪制MSBar2D圖的相關實現(xiàn)技巧,并附帶demo源碼供讀者下載,需要的朋友可以參考下2017-03-03方便實用的jQuery checkbox復選框全選功能簡單實例
這篇文章介紹了jQuery checkbox復選框全選功能的代碼實例,有需要的朋友可以參考一下2013-10-10jquery實現(xiàn)帶復選框的表格行選中刪除時高亮顯示
在實際的應用中可能會出現(xiàn)表格中帶復選框的,刪除時,將復選框所在的行的記錄刪除。在這的地方,可以加個特效,單擊某行的同時將該行的復選框選中,該行的背景色也高亮顯示2013-08-08jq stop()和:is(:animated)的用法及區(qū)別(詳解)
下面小編就為大家?guī)硪黄猨q stop()和:is(:animated)的用法及區(qū)別(詳解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02