有時候網頁太長的時候,常常會覺得要一直推滑鼠滾輪回到最上方覺得麻煩,這裡要分享一鍵回到頂部的方法
下面是程式的代碼
HTML 的部份可隨意放在任何地方,只需複製 id="gotop" 那段即可
CSS 一樣只要複製 #gotop 就可以了
提醒重要一點,使用前必須先載入 jQuery Library
CSS 一樣只要複製 #gotop 就可以了
提醒重要一點,使用前必須先載入 jQuery Library
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
$(function() {
$.fn.LoadingImg = function() {
return this.each(function() {
var that = this;
var src = $(this).attr("src2"); //取得當前src2的屬性
var img = new Image(); //建立新的圖片
img.src = src;
var loading = $("<img src='loading.gif' >"); //讀取的圖片
$(this).after(loading); //加入讀取的圖片
$(this).hide(); //隱藏目前的圖片
$(img).load(function() { //讀取完畢後
loading.remove();
$(that).attr("src", src);
$(that).show();
});
});
};
$("img").LoadingImg();
});
<img src2="demo.jpg">