最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js模仿windows桌面圖標(biāo)排列算法具體實(shí)現(xiàn)(附圖)

 更新時(shí)間:2013年06月16日 16:02:12   作者:  
需要引入Jquery,如果需要全部功能,請(qǐng)引入jquery-ui和jquery-ui.css,具體實(shí)現(xiàn)步驟如下,感興趣的朋友可以參考下哈
注:需要引入Jquery
如果需要全部功能,請(qǐng)引入jquery-ui和jquery-ui.css
截圖:
 
js代碼:
復(fù)制代碼 代碼如下:

$(function() {

//菜單列表
var menu_list=$(".menu-list");

//工作區(qū)
var working=$(".working");

working.click(function() {
menu_list.hide();
$(".content-menu").hide("slow");
});

//菜單圖標(biāo)單擊
$(".menu").bind("click",function() {
menu_list.show();

});
arrange();

$(window).resize(function() {
arrange();
});

//屏蔽右鍵菜單
$(document).contextmenu(function() {
return false;
});

//點(diǎn)擊工作區(qū)的時(shí)候 顯示右鍵菜單
$(".working").contextmenu(function(event) {

var x=event.clientX;
var y=event.clientY;
var menu=$(".content-menu");

//判斷坐標(biāo)
var width=document.body.clientWidth;
var height=document.body.clientHeight;

x=(x+menu.width())>=width?width-menu.width():x;
y=(y+menu.height())>=height-40?height-menu.height():y;

//alert("可視高度:"+height+",鼠標(biāo)高度:"+y);
menu.css("top",y);
menu.css("left",x);
menu.show();


});

//content-menu
$(".content-menu ul li").click(function() {
var text=$(this).text();

switch (text) {
case "刷新":
document.location.reload();
break;
case "退出登錄":
if(confirm("是否要退出登錄?")){

}
break;
default:
break;
}

$(".content-menu").hide();
});
});
//排列圖標(biāo)部分
function arrange(){
var ul=$(".icons");
var working=$(".working");
//位置坐標(biāo)
var position={x:0,y:0,bottom:110,width:50,height:50,parent:{height:0,width:0},padding:{top:10,left:10,right:0,bottom:10}};

position.parent.height=working.height()-40;
position.parent.width=working.width();

ul.find("li").each(function(index) {

$(this).css("top",position.y+"px");
$(this).css("left",position.x+"px");

position.height=$(this).height();
position.width=$(this).width();

position.y=position.y+position.height+position.padding.bottom+position.padding.bottom;

if(position.y>=position.parent.height-position.bottom){
position.y=0;
position.x=position.x+position.width+position.padding.left;
}
});
}

html代碼:
復(fù)制代碼 代碼如下:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD LEVEL1//EN">
<html>
<head>
<title>index.html</title>

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=GBK">
<link rel="stylesheet" type="text/css" href="css/window.css">
<link rel="stylesheet" type="text/css" href="css/jquery-ui.css">
<script language="JavaScript" src="js/jquery-1.10.0.js"></script>
<script language="JavaScript" src="js/jquery-ui.js"></script>
<script language="JavaScript" src="js/window.js"></script>
</head>
<body>

<div class="working">

<ul class="icons">

<script>
for (var i = 1; i <= 4; i++) {
var html = "";
html += '<li>';
html += '<img src="images/'+i+'.gif">';
html += '<div class="text">圖標(biāo)'+i+'</div>';
html += '</li>';
document.write(html);
}
</script>

</ul>

</div>


<div class="taskbar">
<div class="menu-list">
<ul>
<li></li>
</ul>
</div>

<div class="menu">

<div class="menu-icon">
<ul><li></li><li></li><li></li><li></li></ul>
</div>

<a href="javascript:;"></a>
</div>

</div>

<div class="window" title="窗體">窗體</div>

<div class="content-menu">
<ul>
<li><a href="javascript:;">刷新</a></li>
<li><a href="javascript:;">設(shè)置</a></li>
<hr/>
<li><a href="javascript:;">幫助</a></li>
<hr/>
<li><a href="javascript:;">關(guān)于</a></li>
<hr/>
<li><a href="javascript:;">系統(tǒng)設(shè)置</a></li>
<li><a href="javascript:;">退出登錄</a></li>
</ul>
</div>


<script>

$(".icons li").mousemove(function(){
$(this).addClass("icons-move");
});

$(".icons li").mouseout(function(){
$(this).removeClass("icons-move");
});

$(".icons li").mousedown(function(){
$(".icons li").removeClass("icons-focus");
$(this).addClass("icons-focus");
//改變當(dāng)前的索引
$(".icons li").css("z-index",0);
$(this).css("z-index",1);
});

$(".icons li").dblclick(function(){
alert("double click");
});

//按鍵事件
$(document).keyup(function(event){
var UP=38;
var DOWM=40;
var ENTER=13;
var elem=$(".icons-focus");

if(elem.html()=="undefined")return;

if (event.keyCode == UP) {
$(".icons li").removeClass("icons-focus");
elem.prev().addClass("icons-focus");
}

if(event.keyCode==DOWM){
$(".icons li").removeClass("icons-focus");
elem.next().addClass("icons-focus");
}

//回車(chē)打開(kāi)選中的圖標(biāo)
if(event.keyCode==ENTER){
var open=$(".icons-focus");
alert("ok enevt is enter");
}

});

//圖標(biāo)拖拽
$(".icons li").draggable();

//注冊(cè)resize事件
$(".window").draggable({containment: 'parent'});
$(".window").resizable({containment: 'parent'});

</script>
</body>
</html>

CSS代碼:
復(fù)制代碼 代碼如下:

@CHARSET "UTF-8";
body, html {
overflow: hidden;
height: 100%;
width: 100%;
margin: 0px;
padding: 0px;
}
.working {
height: 100%;
width: 100%;
background-image: url("../images/untitled.png");
background-repeat: no-repeat;
background-color: rgb(235, 236, 238);
padding: 20px;
}
.working ul {
height: 100%;
position: relative;
}
.working ul li {
position: absolute;
display: block;
width: 90px;
height: 90px;
text-align: center;
margin: 0px 10px 10px 10px;
float: left;
border: inherit 1px inherit;
overflow: hidden;
cursor: pointer;
}
.taskbar {
position: absolute;
height: 35px;
line-height: 35px;
width: 100%;
bottom: 0px;
background-color: #CCC;
z-index: 999;
filter: alpha(opacity = 80);
opacity: 0.8;
padding: 0px 10px;
}
.menu {
display: block;
width: 50px;
height: 30px;
float: left;
}
.menu-list {
position: absolute;
left: 0px;
bottom: 35px;
width: 350px;
height: 500px;
border: #CCC 1px solid;
background-color: white;
filter: alpha(opacity = 90);
opacity: 0.9;
border-radius: 5px;
display: none;
}
ul {
margin: 0px;
padding: 0px;
}
.menu-icon {
cursor: pointer;
}
.menu-icon ul li {
display: block;
width: 15px;
height: 15px;
float: left;
margin: 1px;
background-color: white;
border-radius: 3px;
}
.menu-icon:hover li {
background-color: red;
}
.icons li img {
max-height: 70px;
max-width: 90px;
}
.text {
position: static;
height: 20px;
line-height: 20px;
width: 100%;
margin: 0px;
font-size: 12px;
font-family: 微軟雅黑;
color: white;
}
.icons-move {
border: rgb(161, 194, 219) 1px solid;
background-color: rgb(194, 208, 226);
filter: alpha(opacity = 60);
opacity: 0.6;
border-radius: 3px;
}
.icons-focus {
border: rgb(161, 194, 219) 1px solid;
background-color: rgb(194, 208, 226);
filter: alpha(opacity = 100);
opacity: 1;
border-radius: 3px;
}
.window {
height: 200px;
width: 200px;
border: #CCC 1px solid;
background-color: white;
border-radius: 5px;
position: absolute;
top: 0px;
z-index: 10;
}
/*
* 右鍵菜單
*/
.content-menu {
position: absolute;
width: 150px;
height: auto;
background-color: rgb(255, 255, 255);
border: #CCC 1px solid;
display: none;
border-radius:5px;
z-index:999;
}
.content-menu ul {
margin: 0px;
padding: 0px;
}
.content-menu ul li {
list-style: none;
line-height: 30px;
height: 30px;
margin: 3px 0px;
padding:0px;
font-size: 13px;
}
.content-menu ul li a{
text-decoration:none;
display:block;
font-family: 微軟雅黑;
padding:0px 5px;
width:140px;
height:100%;
color: #333;
outline:none;

}
.content-menu ul li a:hover {
background-color: #DDD;
}
.content-menu ul hr {
margin: 1px 0px;
height: 0px;
border: 0px;
border-bottom: #CCC 1px solid;
}

相關(guān)文章

  • javascript中的offsetWidth、clientWidth、innerWidth及相關(guān)屬性方法

    javascript中的offsetWidth、clientWidth、innerWidth及相關(guān)屬性方法

    這篇文章主要介紹了javascript中的offsetWidth、clientWidth、innerWidth及相關(guān)屬性方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2020-05-05
  • javascript實(shí)現(xiàn)根據(jù)漢字獲取簡(jiǎn)拼

    javascript實(shí)現(xiàn)根據(jù)漢字獲取簡(jiǎn)拼

    這里給大家分享一個(gè)JavaScript實(shí)現(xiàn)的根據(jù)漢字可以自動(dòng)轉(zhuǎn)換簡(jiǎn)拼代碼,有需要的朋友可以參考一下,并非本人原創(chuàng)來(lái)自網(wǎng)絡(luò)。
    2016-09-09
  • JavaScript通過(guò)HTML的class來(lái)獲取HTML元素的方法總結(jié)

    JavaScript通過(guò)HTML的class來(lái)獲取HTML元素的方法總結(jié)

    除了getElementsByClassName()函數(shù),我們可以自己動(dòng)手編寫(xiě)程式來(lái)通過(guò)class獲取元素,接下來(lái)我們整理了一下JavaScript通過(guò)HTML的class來(lái)獲取HTML元素的方法總結(jié),需要的朋友可以參考下
    2016-05-05
  • JavaScript實(shí)現(xiàn)日期格式化的操作詳解

    JavaScript實(shí)現(xiàn)日期格式化的操作詳解

    在我們做業(yè)務(wù)開(kāi)發(fā)的漫長(zhǎng)歲月里,會(huì)多次跟時(shí)間打交道,相信大多數(shù)小伙伴對(duì)日期格式化也并不陌生,本文簡(jiǎn)單記錄了JavaScript實(shí)現(xiàn)日期格式化的過(guò)程,以及一些拓展,希望對(duì)大家有所幫助
    2023-05-05
  • 解析OpenLayers 3加載矢量地圖源的問(wèn)題

    解析OpenLayers 3加載矢量地圖源的問(wèn)題

    矢量圖形最大的優(yōu)點(diǎn)是無(wú)論放大、縮小或旋轉(zhuǎn)等不會(huì)失真。在地圖中存在著大量的應(yīng)用,是地圖數(shù)據(jù)中非常重要的組成部分,這篇文章主要介紹了OpenLayers 3加載矢量地圖源的相關(guān)資料,需要的朋友可以參考下
    2021-12-12
  • JavaScript模擬實(shí)現(xiàn)簡(jiǎn)單的MVC的示例詳解

    JavaScript模擬實(shí)現(xiàn)簡(jiǎn)單的MVC的示例詳解

    MVC是一種常見(jiàn)的軟件架構(gòu)模式,MVC模式的目的是將應(yīng)用程序的數(shù)據(jù)、用戶(hù)界面和控制邏輯分離,提高代碼的可維護(hù)性,可拓展性和可重用性。本文就來(lái)用用JS模擬實(shí)現(xiàn)一個(gè)簡(jiǎn)單的MVC吧
    2023-04-04
  • 微信小程序中使用echarts方法(全網(wǎng)最詳細(xì)教程!)

    微信小程序中使用echarts方法(全網(wǎng)最詳細(xì)教程!)

    現(xiàn)在越來(lái)越多的項(xiàng)目都在使用可視化的功能,那么使用echarts實(shí)現(xiàn)是一種不錯(cuò)的選擇,下面這篇文章主要給大家介紹了關(guān)于小程序中使用echarts的方法,本文介紹的方法應(yīng)該是全網(wǎng)最詳細(xì)教程,需要的朋友可以參考下
    2023-06-06
  • bootstrap-table+treegrid實(shí)現(xiàn)樹(shù)形表格

    bootstrap-table+treegrid實(shí)現(xiàn)樹(shù)形表格

    這篇文章主要為大家詳細(xì)介紹了bootstrap-table+treegrid實(shí)現(xiàn)樹(shù)形表格,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-07-07
  • JS預(yù)覽圖像將本地圖片顯示到瀏覽器上

    JS預(yù)覽圖像將本地圖片顯示到瀏覽器上

    本代碼從file域獲取本地圖片url并將本地圖片顯示到瀏覽器上,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助
    2013-08-08
  • JavaScript中的垃圾回收與內(nèi)存泄漏示例詳解

    JavaScript中的垃圾回收與內(nèi)存泄漏示例詳解

    這篇文章主要給大家介紹了關(guān)于JavaScript中垃圾回收與內(nèi)存泄漏的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用JavaScript具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-05-05

最新評(píng)論

清原| 蚌埠市| 尼勒克县| 鄂托克旗| 建德市| 凤庆县| 齐河县| 甘泉县| 科尔| 江城| 八宿县| 岑巩县| 沁水县| 隆昌县| 沙坪坝区| 博乐市| 聂拉木县| 江阴市| 宜城市| 东辽县| 建平县| 涟源市| 乾安县| 五河县| 静乐县| 连南| 湟源县| 澄江县| 介休市| 新郑市| 潢川县| 丹江口市| 东山县| 陇西县| 中江县| 洞口县| 敦煌市| 翼城县| 高雄市| 金平| 黄梅县|