常常遇到圖片透過後台上傳後就變形了的問題,如果你的網站風格適合,可以用這種方式來給頁面佈局,支援任意尺寸的圖片滑動(上下左右滑動)
<! DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>任意尺寸的图片滑动</title> <style> div { margin: 0 auto; overflow: hidden;} .main { width: 1000px;} .divimg_div1 { width: 380px; float: left;} .divimg .div4_title { width: 380px; height: 103px; background-color: #EDB205; color: #FFF; font-family: "微软雅黑"; font-size: 22px; font-weight: bold; line-height: 90px; text-align: center; letter-spacing: 5px;} .divimg_img1 { width: 380px; height: 414px; margin-top: 5px; background-color: #FFF; position: relative;} .divimg_div2 { width: 615px; float: right;} .divimg_img2 { width: 194px; height: 256px; float: left; background-color: #FFF; position: relative;} .divimg_img3 { width: 417px; height: 256px; float: right; background-color: #FFF; position: relative;} .divimg_img4 { width: 366px; height: 262px; float: left; margin-top: 4px; background-color: #FFF; position: relative;} .divimg_img5 { width: 245px; height: 262px; float: right; margin-top: 4px; background-color: #FFF; position: relative;} .divimg .gif { position: absolute; left: 50%; top: 50%; margin-left: -50px; margin-top: -50px; z-index: 2;} .divimg .img { position: absolute; z-index: 1; left: 0; top: 0; display: none;} </style> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function(e) { $(".divimg .img").load(function(){ var w=parseInt($(this).width()); var h=parseInt($(this).height()); var hh=$(this).parent().height(); var ww=$(this).parent().width(); var blw=w/parseInt(ww); var blh=h/parseInt(hh); function left(){ $(this).animate({left:-(parseInt(parseInt(hh)/h*w)-(parseInt(ww)))},10000,right) } function right(){ $(this).animate({left:0},10000,left); } function top(){ $(this).animate({top:-(parseInt(parseInt(ww)/w*h)-(parseInt(hh)))},10000,bottom); } function bottom(){ $(this).animate({top:0},10000,top); } if(blw > blh) { $(this).height(hh).width(parseInt(parseInt(hh)/h*w)); $(this).prev().hide(); $(this).css({"z-index":"3","display":"block"}); $(this).animate({left:-(parseInt(parseInt(hh)/h*w)-(parseInt(ww)))},10000,right); } else if(blw < blh) { $(this).height(parseInt(parseInt(ww)/w*h)).width(ww); $(this).prev().hide(); $(this).css({"z-index":"3","display":"block"}); $(this).animate({top:-(parseInt(parseInt(ww)/w*h)-(parseInt(hh)))},10000,bottom); } }); $(".div4 .img").each(function(index, element) { $(this).attr("src",$(this).attr("name")); }); }); </script> </head> <body> <div class="main"> <div class="divimg"> <div class="divimg_div1"> <div class="divimg_title">任意尺寸的图片滑动</div> <div class="divimg_img1"> <img class="gif lazy" src="/static/imghwm/default1.png" data-src="images/loadding.gif" style="max-width:90%" style="max-width:90%" / alt="一張支援任意尺寸的圖片上下左右滑動效果_jquery" > <img class="img" name="images/am_bigimg01.jpg" src="" / alt="一張支援任意尺寸的圖片上下左右滑動效果_jquery" > </div> </div> <div class="divimg_div2"> <div class="divimg_img2"> <img class="gif lazy" src="/static/imghwm/default1.png" data-src="images/loadding.gif" style="max-width:90%" style="max-width:90%" / alt="一張支援任意尺寸的圖片上下左右滑動效果_jquery" > <img class="img" name="images/am_nyimg01.jpg" src="" / alt="一張支援任意尺寸的圖片上下左右滑動效果_jquery" > </div> <div class="divimg_img3"> <img class="gif lazy" src="/static/imghwm/default1.png" data-src="images/loadding.gif" style="max-width:90%" style="max-width:90%" / alt="一張支援任意尺寸的圖片上下左右滑動效果_jquery" > <img class="img" name="images/am_img02.jpg" src="" / alt="一張支援任意尺寸的圖片上下左右滑動效果_jquery" > </div> <div class="divimg_img4"> <img class="gif lazy" src="/static/imghwm/default1.png" data-src="images/loadding.gif" style="max-width:90%" style="max-width:90%" / alt="一張支援任意尺寸的圖片上下左右滑動效果_jquery" > <img class="img" name="images/am_newimg01.jpg" src="" / alt="一張支援任意尺寸的圖片上下左右滑動效果_jquery" > </div> <div class="divimg_img5"> <img class="gif lazy" src="/static/imghwm/default1.png" data-src="images/loadding.gif" style="max-width:90%" style="max-width:90%" / alt="一張支援任意尺寸的圖片上下左右滑動效果_jquery" > <img class="img" name="images/am_rynewimg03.jpg" src="" / alt="一張支援任意尺寸的圖片上下左右滑動效果_jquery" > </div> </div> </div> </div> </body> </html>

JavaScript字符串替換方法詳解及常見問題解答 本文將探討兩種在JavaScript中替換字符串字符的方法:在JavaScript代碼內部替換和在網頁HTML內部替換。 在JavaScript代碼內部替換字符串 最直接的方法是使用replace()方法: str = str.replace("find","replace"); 該方法僅替換第一個匹配項。要替換所有匹配項,需使用正則表達式並添加全局標誌g: str = str.replace(/fi

因此,在這裡,您準備好了解所有稱為Ajax的東西。但是,到底是什麼? AJAX一詞是指用於創建動態,交互式Web內容的一系列寬鬆的技術。 Ajax一詞,最初由Jesse J創造

10款趣味橫生的jQuery遊戲插件,讓您的網站更具吸引力,提升用戶粘性!雖然Flash仍然是開發休閒網頁遊戲的最佳軟件,但jQuery也能創造出令人驚喜的效果,雖然無法與純動作Flash遊戲媲美,但在某些情況下,您也能在瀏覽器中獲得意想不到的樂趣。 jQuery井字棋遊戲 遊戲編程的“Hello world”,現在有了jQuery版本。 源碼 jQuery瘋狂填詞遊戲 這是一個填空遊戲,由於不知道單詞的上下文,可能會產生一些古怪的結果。 源碼 jQuery掃雷遊戲

本教程演示瞭如何使用jQuery創建迷人的視差背景效果。 我們將構建一個帶有分層圖像的標題橫幅,從而創造出令人驚嘆的視覺深度。 更新的插件可與JQuery 1.6.4及更高版本一起使用。 下載

Matter.js是一個用JavaScript編寫的2D剛體物理引擎。此庫可以幫助您輕鬆地在瀏覽器中模擬2D物理。它提供了許多功能,例如創建剛體並為其分配質量、面積或密度等物理屬性的能力。您還可以模擬不同類型的碰撞和力,例如重力摩擦力。 Matter.js支持所有主流瀏覽器。此外,它也適用於移動設備,因為它可以檢測觸摸並具有響應能力。所有這些功能都使其值得您投入時間學習如何使用該引擎,因為這樣您就可以輕鬆創建基於物理的2D遊戲或模擬。在本教程中,我將介紹此庫的基礎知識,包括其安裝和用法,並提供一

本文演示瞭如何使用jQuery和ajax自動每5秒自動刷新DIV的內容。 該示例從RSS提要中獲取並顯示了最新的博客文章以及最後的刷新時間戳。 加載圖像是選擇

本文討論了在瀏覽器中優化JavaScript性能的策略,重點是減少執行時間並最大程度地減少對頁面負載速度的影響。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3 英文版
推薦:為Win版本,支援程式碼提示!

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

MantisBT
Mantis是一個易於部署的基於Web的缺陷追蹤工具,用於幫助產品缺陷追蹤。它需要PHP、MySQL和一個Web伺服器。請查看我們的演示和託管服務。

WebStorm Mac版
好用的JavaScript開發工具

EditPlus 中文破解版
體積小,語法高亮,不支援程式碼提示功能